转: window中使用PSFTP/WinSCP实现SFTP上传下载
sftp 服务器: dbmonitor
1、sftp属于交互式的,所以你得缓存下命令
#!/bin/sh
sftp -o Port=3322
root@172.16.1.21:/opt << !
mput *.log
!
2、用scp一行搞定
scp -P3322 /opt/*.txt root@172.16.1.22:/tmp
3、用rsync同步整个目录
rsync -av '-e ssh -p 3322' /data/test root@172.16.1.23:/data
远端client 服务器
scp 192.168.4.45:/home/oracle/*.zip .
摘自百度百科
sftp 与 ftp 有着几乎一样的语法和功能。
SFTP 为 SSH的一部份,是一种传输档案至 Blogger 伺服器的安全方式。
其实在SSH软件包中,已经包含了一个叫作SFTP(Secure File Transfer Protocol的安全文件传输子系统,SFTP本身没有单独的守护进程,它必须使用sshd守护进程(端口号默认是22)来完成相应的连接操作,所以从某种意义上来说,SFTP并不像一个服务器程序,而更像是一个客户端程序。SFTP同样是使用加密传输认证信息和传输的数据,所以,使用SFTP是非常安全的。
但是,由于这种传输方式使用了加密/解密技术,所以传输效率比普通的FTP要低得多,如果您对网络安全性要求更高时,可以使用SFTP代替FTP。
1.WinSCP部分
1.1 cmd命令行实例
winscp>
1.2 Batch批处理实例
将下面语句存入1.txt:
option batch on option confirm off # Connect using a password # open 用户名:密码@主机 # Connect open 用户名:密码@主机 cd /home/user option transfer binary get /root/test.c d:/ put d:/test.txt close exit
执行脚本
1.3 C#程序实现
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics;
namespace SFTP { public class WinSCPtest { public string shellName { get { return "D:\\winscp437\\WinSCP.com"; } } public string userName { get { return "username"; } } public string userPassWord { get { return "userpassword"; } } public string serverAddress { get { return "172.0.0.1"; } } public string portNumber { get { return "21"; } } public string fromFile { get { return "D:\\psftp.txt"; } } public string toFile { get { return "WinSCP/psftp.txt"; } } public void upload() { Process CommandLine = new Process(); CommandLine.StartInfo.FileName = shellName; // CommandLine.StartInfo.Arguments = "/log=" + this._logPath; CommandLine.StartInfo.UseShellExecute = false; CommandLine.StartInfo.RedirectStandardInput = true; CommandLine.StartInfo.RedirectStandardOutput = true; CommandLine.StartInfo.CreateNoWindow = true; CommandLine.Start(); //username用户名 targetAddress IP地址 portNumber 端口号 CommandLine.StandardInput.WriteLine("open ftp://{0}:{1}@{2}:{3}", this.userName,this.userPassWord, this.serverAddress, this.portNumber); //上传文件到sftp服务器 string command = "put " + fromFile + " " + toFile ; //fromFile要传送的文件路径本地的绝对路径 toFile服务器上保存文件的路径相对路径 CommandLine.StandardOutput.DiscardBufferedData(); CommandLine.StandardInput.WriteLine(command); string result = CommandLine.StandardOutput.ReadLine(); } } }
1.4 在线资源
http://winscp.net/eng/docs/commandline
2.SFTP部分
2.1 cmd命令行实例
C:\Documents and Settings\sobne>e:
2.2 Batch批处理实例
将下面语句存入myscript.scr:
cd / put File1.txt put File2.txt put File3.txt close
执行脚本
2.3 C#程序实现
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.Threading;
namespace Lib4Net {
public class PSFTPunity { public string shellCommand { get; set; }
public string serverName { get; set; } public string userName { get; set; } public string privateKey { get; set; }
public PSFTPunity() { } public PSFTPunity(string shell, string server, string user, string ppk) { shellCommand = shell; serverName = server; userName = user; privateKey = ppk; } /// <summary> /// Upload the files /// </summary> /// <param name="localFile">localfile fullname</param> /// <param name="remotePath">remotefile fullname</param> /// <returns>output of the plugin during its running in console</returns> public string Upload(string localFile, string remotePath) { string outPutMessage = "";
ProcessStartInfo processInfo = new ProcessStartInfo(); processInfo.FileName = this.shellCommand; processInfo.CreateNoWindow = true; processInfo.UseShellExecute = false; processInfo.RedirectStandardError = true; processInfo.RedirectStandardInput = true; processInfo.RedirectStandardOutput = true; string arguments = ""; arguments += userName + "@" + serverName + " "; arguments += "-i " + privateKey; processInfo.Arguments = arguments;
Process process = new Process(); try { process.StartInfo = processInfo; process.Start(); Thread.Sleep(5000); process.StandardInput.WriteLine("n"); Thread.Sleep(2000); //process.StandardInput.WriteLine("cd " + remotePath); process.StandardInput.WriteLine("put " + localFile + " " + remotePath); //process.StandardInput.Close(); Thread.Sleep(10000); //outPutMessage += process.StandardOutput.ReadToEnd(); //outPutMessage += process.StandardError.ReadToEnd(); process.WaitForExit(3000); process.Close(); return outPutMessage; } catch (Exception ex) { throw new Exception("Error occured during upload file to remote server!", ex); } finally { process.Dispose(); } } } }
2.4 在线资源
文中使用的软件下载地址:http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
转: window中使用PSFTP/WinSCP实现SFTP上传下载的更多相关文章
- THINKPHP 3.2 PHP SFTP上传下载 代码实现方法
一.SFTP介绍:使用SSH协议进行FTP传输的协议叫SFTP(安全文件传输)Sftp和Ftp都是文件传输协议.区别:sftp是ssh内含的协议(ssh是加密的telnet协议), 只要sshd服 ...
- Xshell5下利用sftp上传下载传输文件
sftp是Secure File Transfer Protocol的缩写,安全文件传送协议.可以为传输文件提供一种安全的加密方法.sftp 与 ftp 有着几乎一样的语法和功能.SFTP 为 SSH ...
- java:工具(汉语转拼音,压缩包,EXCEL,JFrame窗口和文件选择器,SFTP上传下载,FTP工具类,SSH)
1.汉语转拼音: import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pinyin4j.format.HanyuP ...
- Java Sftp上传下载文件
需要使用jar包 jsch-0.1.50.jar sftp上传下载实现类 package com.bstek.transit.sftp; import java.io.File; import ja ...
- SFTP上传下载文件、文件夹常用操作
SFTP上传下载文件.文件夹常用操作 1.查看上传下载目录lpwd 2.改变上传和下载的目录(例如D盘):lcd d:/ 3.查看当前路径pwd 4.下载文件(例如我要将服务器上tomcat的日志文 ...
- java实操之使用jcraft进行sftp上传下载文件
sftp作为临时的文件存储位置,在某些场合还是有其应景的,比如对账文件存放.需要提供一个上传的工具类.实现方法参考下: pom.xml中引入类库: <dependency> <gro ...
- java 实现Serv-U FTP 和 SFTP 上传 下载
两种ftp使用java的实现方式 ,代码都已测试 第一种:Serv-U FTP 先决条件: 1.Serv-U FTP服务器搭建成功. 2.jar包需要:版本不限制 <!--ftp上传需要的jar ...
- sftp 上传下载 命令介绍
sftp是Secure FileTransferProtocol的缩写,安全文件传送协议.可以为传输文件提供一种安全的加密方法. sftp与 ftp有着几乎一样的语法和功能.SFTP为 SSH的一部分 ...
- JSP+Servlet中使用jspsmartupload.jar进行图片上传下载
JSP+Servlet中使用cos.jar进行图片上传 upload.jsp <form action="FileServlet" method="post&quo ...
随机推荐
- 《C++ Primer》之面向对象编程(二)
构造函数和复制控制 每个派生类对象由派生类中定义的(非 static)成员加上一个或多个基类子对象构成,当我们构造.复制.赋值和撤销一个派生类对象时,也会构造.复制.赋值和撤销这些基类子对象. 构造函 ...
- PostMessage 向Windows窗口发送Alt组合键
PostMessage 向Windows窗口发送Alt组合键 关于向Windows窗口发送Alt组合键的问题,这个真是经典问题啊,在网上找了一下,问的人N多,方法差不多, 但就是没有很好解决问题. 之 ...
- hdu_3518_Boring counting(后缀数组)
题目链接:hdu_3518_Boring counting 题意: 给你一个字符串,让你找不重叠且出现大于1次以上的字串个数 题解: 后缀数组height数组的应用,我们枚举字串的长度,然后将heig ...
- redis第一篇--综述
1 redis里边有数据库的概念.可分为1-255这些表.在存储或者查找的时候要指明. redis_sentinel 集群里边封装成了namespace这样的概念.与db是不一样的.
- Git add和commit步骤分析
修改后或者添加新的文件,执行add命令后,首先它会先存入本地库的暂存区, add可以上传很多个文件,然后执行commit命令后,都会被提交到默认的分支 Master分支上.只有文件更改和文件新建,都可 ...
- 修改NavigationBar样式
iOS Tip: Change Status Bar Icon & Text Colors When iOS 7 was introduced Apple allowed your appli ...
- NTP服务器时间同步
CentOS 配置服务器NTP同步 1 查看是否安装 rpm -aq | grep ntp 2 安装 yum -y install ntp 3 配置 /etc/ntp.conf restrict 访问 ...
- "Debugging not possible in single session mode"
PLSQL Developer在测试存储过程,遇到"Debugging not possible in single session mode" 解决办法: 点击菜单栏" ...
- UICollectController
九宫格 UICollectController 1.新建一个xib描述cell 2.注册xib 3.collectionView显示cell *必须设置数据源(和代理并遵守协议) *实现数据源和代理的 ...
- ant 配置 和测试 1
配置路径 D:\dba\change\UAT\unity\schema\test ----v0 版本 sql.xml (默认target 是versionfinal ,也就是最终版本) --ver ...