简体   繁体   English

如何使用sftp上传目录

[英]how to upload a directory with sftp

I am building a java web based application. 我正在构建一个基于Java Web的应用程序。 To upload a directory and the files in it from my user's client to my server machine I am using a client-side Java applet which supports only ftp. 要将目录及其中的文件从用户的客户端上载到服务器计算机,我正在使用仅支持ftp的客户端Java小程序。

How do I upload a directory full of files using sftp and java? 如何使用sftp和java上传一个充满文件的目录?

"Only ftp" will not do with "sftp". “仅ftp”与“ sftp”不兼容。 Either you need an sftp-applet or to have ftp enabled on your server. 您需要一个sftp-applet或在服务器上启用ftp。

Using SFTP is a good idea, because FTP suffers from some security problems. 使用SFTP是一个好主意,因为FTP存在一些安全问题。

You are going to need to find SFTP client classes to use in the Java client applet which you will provide to your users, in place of the FTP classes you use now. 您将需要找到要在Java客户端小程序中使用的SFTP客户端类,该类将提供给用户,而不是现在使用的FTP类。

And, you are going to need to install an SFTP server software package on your server hardware, so your client applet has something to which to connect. 并且,您将需要在服务器硬件上安装SFTP服务器软件包,以便客户端小程序可以连接到某些东西。 (It's possible your server hardware already has this package. In that case you need to activate it and configure it.) (您的服务器硬件可能已经安装了此软件包。在这种情况下,您需要激活并配置它。)

Finally, you need to understand that SFTP and FTP don't really offer the primitive operation "upload a directory." 最后,您需要了解SFTP和FTP并没有真正提供原始操作“上传目录”。 Your client Java software will need to figure out how to upload all the files in the directory on your user's machine. 您的客户端Java软件将需要弄清楚如何上载用户计算机上目录中的所有文件。

I'm using JSCH aip( Link ) for contributing sftp application. 我正在使用JSCH aip( Link )贡献sftp应用程序。 Jsch has no method helping upload directory, you can get all file path in the directory you want to download and then pass them to the upload method (put(....) in ChannelSftp class). Jsch没有帮助上传目录的方法,您可以在要下载的目录中获取所有文件路径,然后将它们传递给上传方法(ChannelSftp类中的put(....))。

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

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