通过 FTP/SFTP 解析远程 $HOME 目录
在 Objective-C 中,NSString 有一个名为的方法,
stringByExpandingTildeInPath
该方法将采用“~/Documents”之类的字符串并将其解析为“/Users/Nick/Documents”。 “~”波浪号被解析为运行程序的计算机的当前用户的主目录。
现在我的问题是……我正在使用 Cocoa 和 Objective-C 编写一个小 FTP/SFTP 实用程序。 如何通过 FTP/SFTP 解析远程计算机上的波形符 (~) 路径?
例如。 用户想要上传文件到
sftp://remote-host.com:~/
如果remote-host.com是Linux或OSX服务器,那么这个路径是完全有效的。 但是,只有当我指定绝对路径时,上传文件才有效。 我不确定这是否是我正在使用的框架的限制, ConnectionKit ,或者如果这是我需要手动实现的东西。 我同意后者,但是,有什么建议吗?
In Objective-C, NSString has a method called
stringByExpandingTildeInPath
This method will take a string like "~/Documents" and resolve it to "/Users/Nick/Documents". The "~" tilde is resolved to the home directory of the current user of the machine the program is running on.
Now my question is this... I am writing a little FTP/SFTP utility using Cocoa and Objective-C. How could I resolve a tilde (~) path on remote machine via FTP/SFTP?
For example. A user wants to upload a file to
sftp://remote-host.com:~/
If remote-host.com is a Linux or OSX server, then this path is totally valid. However uploading a file only works when I specify the absolute path. I'm not sure if this is a limitation of the framework I'm using, ConnectionKit, or if this is something that I need to manually implement. I'm ok with the latter but, any suggestions on how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试仅删除“〜/”(并使用其余部分作为相对路径) - 通常,当您连接时,服务器默认会将您置于用户的主目录中。
You could try just removing the "~/" (and use the rest as a relative path) - generally the server should put you in the user's home directory by default when you connect.