在Windows和Linux之间的FTP事务期间不同的路径分隔符 [英] Different path separators during FTP transaction between windows and linux
问题描述
我通过FTP将文件上传到Linux服务器。我使用Apache的 FTPClient
。
假设我想上传文件 C:\\\ \\下载\\13 \\myFile.txt
到服务器 /data/downloads/13/myFile.txt
在我上传之前,我使用 listFiles
。
$ b
当我说
ftp.listFiles(/ data / downloads / 13) ;
我得到一个包含一个文件对象的数组,这意味着路径存在(并且我不需要创建一个文件夹)。但是,当我说
ftp.listFiles(\\data\\downloads\\13) ;
我得到一个空数组,表示路径不存在。
原因是因为我在Windows机器上运行我的应用程序,所以路径分隔符是不同的。
解决方案I'我决定通过用 /
替换 \
来规范化路径,然后继续进行FTP交易。 p>
这是解决这个问题的正确方法吗?
959:
路径名称
路径名被定义为用户为了识别文件而必须是
输入到文件系统的字符串。
路径名通常包含设备和/或目录名称,以及
文件名称说明。 FTP尚未指定标准的
路径名约定。每个用户都必须遵循传输中涉及的文件系统的
惯例文件。
因为没有路径名标准,如果FTP服务器愿意,FTP服务器可以选择使用其本地文件系统的路径名约定。如果您打算连接到任何其他服务器,则在修改路径名之前,您可能希望向服务器发送SYST请求。
4.1.3。 FTP服务命令
...
SYSTEM(SYST)
该命令用于查找在服务器上运行的
系统的类型。答复的第一个
字是分配号码文件[4]当前版本
中列出的系统名称之一。
实现最小FTP服务器不需要SYST命令,所以该命令可能无法被某些服务器识别。但是,如果该命令已经实施,它将允许您修改路径名以兼容。以下是您可能收到的5个示例回复:
215 UNIX类型:L8
215 UNIX类型:L8版本:BSD -44
215 NetWare系统类型。
215 MACOS彼得的服务器
215 AmigaOS
从您链接的Apache FTPClient文档中,发送SYST请求的函数是我相信的,虽然我不熟悉Java和这个Apache客户端: getSystemType 。
最后, I am uploading a file via FTP to a Linux server. I use Apache's So let's say I wanted to upload the file Before I upload, I determine whether the directory that it will be sent to exists using When I say 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 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. The solution I've decided on is to normalize the paths by replacing Is this the proper way to address this issue? From RFC 959: pathname
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 '/'. 这篇关于在Windows和Linux之间的FTP事务期间不同的路径分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!FTPClient
.C:\\downloads\\13\\myFile.txt
to the server at /data/downloads/13/myFile.txt
listFiles
.ftp.listFiles("/data/downloads/13");
ftp.listFiles("\\data\\downloads\\13");
\
with /
before I proceed with the FTP transactions.
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. 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.
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. 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: 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.