2

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?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Ragesh Kr
  • 1,573
  • 8
  • 29
  • 46
  • if you want to do it programatically why dont you use SCP directly? – aryann May 28 '14 at 10:48
  • I havent heard abt SCP sorry , can u help me out with that ??? i Will even try looking into that. – Ragesh Kr May 28 '14 at 10:51
  • @aryann assume i have written the file programatically how do I open a connection by giving the Creds and place the file ?? – Ragesh Kr May 28 '14 at 10:52
  • ragesh, as mentioned by martin using jsch library. There are examples available for what you want to do with jsch. – aryann May 28 '14 at 11:44

1 Answers1

3

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

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992