将本地的文件上传到linux的服务器

首先要使用 SecureCRT 8.1 的工具 打开linux 

然后如图所示

然后选择自己的文件夹就可以了

转载  http://blog.csdn.net/u014568921/article/details/52939063

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的Java代码示例,可以将本地文件上传Linux服务器上: ```java import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import com.jcraft.jsch.Channel; import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.JSch; import com.jcraft.jsch.Session; public class FileUploader { public static void main(String[] args) { String localFilePath = "/path/to/local/file"; String remoteFilePath = "/path/to/remote/file"; String remoteHost = "remote_host"; String remoteUser = "remote_user"; String remotePassword = "remote_password"; int remotePort = 22; try { uploadFile(localFilePath, remoteFilePath, remoteHost, remoteUser, remotePassword, remotePort); System.out.println("File uploaded successfully!"); } catch (Exception e) { e.printStackTrace(); } } public static void uploadFile(String localFilePath, String remoteFilePath, String remoteHost, String remoteUser, String remotePassword, int remotePort) throws Exception { JSch jsch = new JSch(); Session session = jsch.getSession(remoteUser, remoteHost, remotePort); session.setPassword(remotePassword); Properties config = new Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); session.connect(); Channel channel = session.openChannel("sftp"); channel.connect(); ChannelSftp sftpChannel = (ChannelSftp) channel; File localFile = new File(localFilePath); InputStream inputStream = new FileInputStream(localFile); sftpChannel.put(inputStream, remoteFilePath); sftpChannel.exit(); session.disconnect(); } } ``` 需要使用到JSch库,可以在Maven中添加以下依赖: ```xml <dependency> <groupId>com.jcraft</groupId> <artifactId>jsch</artifactId> <version>0.1.55</version> </dependency> ``` 其中,`localFilePath`表示本地文件的路径,`remoteFilePath`表示远程服务器上保存文件的路径,`remoteHost`表示远程服务器的IP地址,`remoteUser`和`remotePassword`表示登录远程服务器的用户名和密码,`remotePort`表示远程服务器的SSH端口号。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值