[英]Transferring file from local machine to server in WinSCP using Java
I want to write a notepad file and upload it to a WinSCP path. 我想编写一个记事本文件并将其上传到WinSCP路径。
I used to create those files manually: Open the WinSCP, give the credentials, open the desired path and upload the file. 我曾经手动创建这些文件:打开WinSCP,提供凭据,打开所需的路径并上传文件。
Now I am in a situation to automate those things. 现在,我处于使这些事情自动化的情况。 Text will be entered in a text box or fetched from DB, it has to be written in a notepad file and should be uploaded to a WinSCP path. 文本将在文本框中输入或从数据库中获取,必须将其写在记事本文件中,并应上载到WinSCP路径。 I have implemented writing the file and it is working fine. 我已经实现了写入文件,并且工作正常。
Now, how do I upload the file using Java? 现在,如何使用Java上传文件?
What you call "WinSCP path" is actually a storage accessible via some file transfer protocol. 您所谓的“ WinSCP路径”实际上是可通过某些文件传输协议访问的存储。 Most typically a FTP or SFTP site. 最通常是FTP或SFTP站点。
For the FTP, you can use for example the URLConnection
class: 对于FTP,可以使用例如URLConnection
类:
Uploading to FTP using Java 使用Java上传到FTP
or the Apache FTPClient
client class: 或Apache FTPClient
客户端类:
FTPClient - Java, upload file FTPClient-Java,上传文件
For the SFTP, you can use JSch Library: 对于SFTP,可以使用JSch库:
How to retrieve a file from a server via SFTP? 如何通过SFTP从服务器检索文件?
If you really want to use WinSCP, you can interact with WinSCP scripting interface from Java. 如果您确实想使用WinSCP,则可以从Java与WinSCP脚本接口进行交互。 See a code sample in the following question: 请参阅以下问题的代码示例:
How to know whether SFTP was successful or not in WinSCP 如何在WinSCP中知道SFTP是否成功
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.