简体   繁体   English

使用Java将文件从本地计算机传输到WinSCP中的服务器

[英]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.

相关问题 用于在Java中将文件从本地计算机同步到远程服务器的命令 - WinSCP - Command for syncing a file from local computer to a remote server in Java - WinSCP 使用javascript和java将文件从服务器下载到本地计算机 - downloading file from server to local machine using javascript and java 如何使用Java将文件从ftp服务器下载到本地计算机 - How to download a file from ftp server to local machine using java 在Windows机器上使用Java Code将本地文件复制到Unix Server? - Copy local file to Unix Server using java Code on windows machine? 将文件目录从Java服务器映射到本地计算机 - map file directory from a java server to local machine 在本地计算机上使用Java从服务器打开目录 - Open directory from server using Java on local machine 使用Jmeter将文件从本地计算机传输到服务器 - Transfer file from local machine to server using Jmeter 如何使用Java自动执行WINSCP文件传输? - How to automate WINSCP file transfer using Java? 我们如何使用Java从本地计算机打开远程计算机上存在的文件? - How can we open a file present on remote machine from local machine using java? 使用Java将文件从本地计算机复制到远程计算机时需要帮助 - Need help in copying a file from local machine to remote machine using java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM