如何使用 C 以编程方式 SCP 文件?
What would be the best way to do an scp
or sftp
copy in a Unix environment using C?
I'm interested in knowing the best library to use and an example if at all possible. I'm working on a Solaris server with the Sun tools installed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
过去,我只是简单地调用包含文件传输代码的 shell 脚本。
如果传输命令成功返回,则返回 1。
In the past, I've simply called a shell script that contained the file transfer code.
This will return 1 if the transfer command returns successfully.
我并不是真正的 C 专家,但我认为您可以使用 system() 来运行操作系统命令。 这假设您实际上不想重新实现 scp,只是使用它。
I'm not really a C expert, but I think you can use system() to run OS commands. This would assume that you don't actually want to re-implement scp, just use it.
我一直只使用 system() 命令。 当然,执行此操作需要您在客户端和目标计算机之间正确安装 SSH 密钥,这样就不会提示输入密码。
I've always just used the system() command. Of course doing this requires that you have SSH keys properly installed between the client and target machine so that it doesn't prompt for the password.
您可以使用 libssh 进行 sftp。 我在这里为您放置了一些具有暂停/恢复功能并可在 Windows 上运行的代码。 对于Linux,您需要替换本地文件处理函数。 我无法复制整个课程,因为它将超出此网站的限制。 将用户名、密码和主机名更改为 SFTP 服务器的正确等效项:
You can use libssh for sftp. I put some code here for you which has Pause/Resume and works on Windows. For Linux, you need to replace local file handling functions. I cannot copy the entire class because it will exceed this website limit. Change username and password and hostname to proper equivalents of your SFTP server:
尝试 Libcurl
Try Libcurl