简体   繁体   中英

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.

I used to create those files manually: Open the WinSCP, give the credentials, open the desired path and upload the file.

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. I have implemented writing the file and it is working fine.

Now, how do I upload the file using Java?

What you call "WinSCP path" is actually a storage accessible via some file transfer protocol. Most typically a FTP or SFTP site.

For the FTP, you can use for example the URLConnection class:
Uploading to FTP using Java
or the Apache FTPClient client class:
FTPClient - Java, upload file

For the SFTP, you can use JSch Library:
How to retrieve a file from a server via SFTP?

If you really want to use WinSCP, you can interact with WinSCP scripting interface from Java. See a code sample in the following question:
How to know whether SFTP was successful or not in WinSCP

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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