转: 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 ...
随机推荐
- js导入插件注意事项.txt
网上收集的答案如下:==============================================1)确认js真的被引用到2)确认js引用顺序没问题3)确认js代码里的括号等都匹配,不会 ...
- Astyle编程语言格式化工具的说明
1.工具->扩展和更新,搜astyle插件,下载安装重启,当前是2.0版本. 2.工具->选项->AStyle Formatter->Edit,填入下面的,点击save,确定. ...
- 《C++ Primer》之指向函数的指针
函数指针是指指向函数而非指向对象的指针.像其他指针一样,函数指针也指向某个特定的类型.函数类型由其返回类型以及形参表确定,而与函数名无关: // pf points to function retur ...
- VBS 读取文本文件特殊字符前如逗号的值并赋值给变量
我使用的仿真终端SecureCRT需要使用一个脚本,支持VBS的.我需要实现如下功能: 首先文本文件在:D:\100.txt文本文件的内容为:9 0,randy,9 1,jeff,9 2,sameul ...
- 十一章:用CSS进行布局
本章重点:盒模型与元素浮动. 盒模型: 1.CSS处理网页时,它认为每个元素都包含在一个不可见的盒子里.这就是众所周知的盒模型,这里的盒子由内容区域.内容区域周围的空间.内边距和外边缘和边框外面将元素 ...
- SharePoint 2010 Modal Dialog
SharePoint 2010 Modal Dialog Tweet Modal dialog play very important role to improve the user exper ...
- Bitmap和Drawable浅谈
一.概念区别 Bitmap - 称作位图,一般位图的文件格式后缀为bmp,当然编码器也有很多如RGB565.RGB8888.作为一种逐像素的显示对象执行效率高,但是缺点也很明显存储效率低.我们理解为一 ...
- su -无反应
一.问题产生环境 CentOS 6.3 X64SecureCRT 7.0.0 英文版 二.问题具体描述 今天操作自己的一台Linux服务器时,突然su命令不好使了,敲入命令回车后,没有任何反应,不管是 ...
- 据磁力链获得BT种子
最近研究了一下磁力链magnet和BT种子torrent文件之间的相互转换.其实通过torrent文件获得磁力链实现起来比较简单,但反过来并非是一个可逆的过程,磁力链转BT种子理论上来说是不可能实现的 ...
- JavaScript的第一次小结
一. JavaScript是一种的脚本语言:特点是:具有解释性,基于对象,事件驱动,安全性和跨平台等特点 对于这几种特点有必要说明一下 解释性:就是JavaScripte本身就是一种解释性语言 基于对 ...