简体   繁体   English

Windows和Linux之间进行FTP事务期间的不同路径分隔符

[英]Different path separators during FTP transaction between windows and linux

I am uploading a file via FTP to a Linux server. 我正在通过FTP将文件上传到Linux服务器。 I use Apache's FTPClient . 我使用Apache的FTPClient

So let's say I wanted to upload the file C:\\\\downloads\\\\13\\\\myFile.txt to the server at /data/downloads/13/myFile.txt 假设我想将文件C:\\\\downloads\\\\13\\\\myFile.txt到服务器上的/data/downloads/13/myFile.txt

Before I upload, I determine whether the directory that it will be sent to exists using listFiles . 上传之前,我使用listFiles确定是否将其发送到的目录。

When I say 当我说

ftp.listFiles("/data/downloads/13");

I get an array containing one file object, meaning that the path exists (and I don't need to create a folder). 我得到一个包含一个文件对象的数组,这意味着该路径存在(并且我不需要创建文件夹)。 However when I say 但是当我说

ftp.listFiles("\\data\\downloads\\13");

I get an empty array, meaning the path does not exist. 我得到一个空数组,这意味着该路径不存在。

The reason for this is because I'm running my application from a Windows machine, so the path separator is different. 这样做的原因是因为我是从Windows计算机上运行应用程序,所以路径分隔符是不同的。

The solution I've decided on is to normalize the paths by replacing \\ with / before I proceed with the FTP transactions. 我已经决定在该解决方案是通过更换正常化的路径\\/前我与FTP交易继续进行。

Is this the proper way to address this issue? 这是解决此问题的正确方法吗?

From RFC 959: 从RFC 959:

pathname 路径名

  Pathname is defined to be the character string which must be input to a file system by a user in order to identify a file. Pathname normally contains device and/or directory names, and file name specification. FTP does not yet specify a standard pathname convention. Each user must follow the file naming conventions of the file systems involved in the transfer. 


Because there is no pathname standard, an FTP server can choose to use the pathname conventions of their local file system if they wish. 因为没有路径名标准,所以FTP服务器可以根据需要选择使用本地文件系统的路径名约定。 You may wish to send a SYST request to the server before you modify your pathname if you intend to connect to any other server. 如果要连接到任何其他服务器,则可能希望在修改路径名之前向服务器发送SYST请求。

4.1.3.  FTP SERVICE COMMANDS
     ...
     SYSTEM (SYST)

            This command is used to find out the type of operating
            system at the server.  The reply shall have as its first
            word one of the system names listed in the current version
            of the Assigned Numbers document [4].


The SYST command is not required for minimum FTP server implementation, so this command may be unrecognized by some servers. 最低FTP服务器实现不需要SYST命令,因此某些服务器可能无法识别此命令。 But if the command has been implemented, it will allow you to modify your pathname to be compatible. 但是,如果该命令已实现,它将允许您修改路径名以使其兼容。 Here are 5 example responses you may receive: 这是您可能会收到的5个示例响应:

 215 UNIX Type: L8
 215 UNIX Type: L8 Version: BSD-44
 215 NetWare system type.
 215 MACOS Peter's Server
 215 AmigaOS


From the Apache FTPClient documentation you have linked to, the function that sends a SYST request is this I believe, although I am unfamiliar with Java and this Apache client: getSystemType . 尽管您不熟悉Java和此Apache客户端: getSystemType ,但是从您链接到的Apache FTPClient文档中,发送SYST请求的函数是这样的。

And lastly an example . 最后是一个例子

But yes, if the server only supports a UNIX pathname you are going to have to convert your Windows pathname from '\\' to '/'. 但是可以,如果服务器仅支持UNIX路径名,则必须将Windows路径名从“ \\”转换为“ /”。

Its the proper way to use the ' / ' but dont know the idea why you want to replace the path seperator before the FTP transactions.But you are running from windows you can provide your full path of windows file as a source with the ' / ' and you can use "/data/downloads/13" as your target. 它是使用'/'的正确方法,但不知道为什么要在FTP事务之前替换路径分隔符。但是,从Windows运行时,您可以使用'/'提供Windows文件的完整路径作为源。 ,您可以使用“ / data / downloads / 13”作为目标。

Provide somemore clarification if I misunderstood it. 如果我误解了,请提供更多说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM