通过 FTP/SFTP 解析远程 $HOME 目录

发布于 2024-07-29 11:31:39 字数 613 浏览 4 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余厌 2024-08-05 11:31:39

您可以尝试仅删除“〜/”(并使用其余部分作为相对路径) - 通常,当您连接时,服务器默认会将您置于用户的主目录中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文