‘壹’ 如何使用FTP上传文件到服务器
使用FTP上传文件到服务器方法如下:
工具:FileZilla
1、双击FileZilla。弹出如下的工作界面
‘贰’ 请教:FTP服务器转移
您在服务器中安装一下FTP服务端软件。
在本地电脑上安装一下FTP客户端,客户端通过服务端的IP、FTP用户名、密码就可以转移数据了。
海腾数据张毅龙为您回答,希望可以帮到您。
‘叁’ C# 将FTP文件转移到另一个FTP服务器上如何实现
C# ftp上传ftp
/// <summary>
/// 上传文件
/// </summary> /
// <param name="fileinfo">需要上传的文件</param>
/// <param name="targetDir">目标路径</param>
/// <param name="hostname">ftp地址</param> /
// <param name="username">ftp用户名</param> /
// <param name="password">ftp密码</param>
public static void UploadFile(FileInfo fileinfo, string targetDir, string hostname, string username, string password)
{ //1. check target
string target;
if (targetDir.Trim() == "")
{ return; }
target = Guid.NewGuid().ToString();
//使用临时文件名
string URI = "FTP://" + hostname + "/" + targetDir + "/" + target;
///WebClient webcl = new WebClient();
System.Net.FtpWebRequest ftp = GetRequest(URI, username, password);
//设置FTP命令 设置所要执行的FTP命令,
//ftp.Method = System.Net.WebRequestMethods.Ftp.ListDirectoryDetails;//假设此处为显示指定路径下的文件列表
ftp.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
//指定文件传输的数据类型
ftp.UseBinary = true;
ftp.UsePassive = true; //告诉ftp文件大小
ftp.ContentLength = fileinfo.Length;
//缓冲大小设置为2KB
const int BufferSize = 2048;
byte[] content = new byte[BufferSize - 1 + 1];
int dataRead; //打开一个文件流 (System.IO.FileStream) 去读上传的文件
using (FileStream fs = fileinfo.OpenRead())
{
try { //把上传的文件写入流
using (Stream rs = ftp.GetRequestStream())
{ do
{ //每次读文件流的2KB
dataRead = fs.Read(content, 0, BufferSize); rs.Write(content, 0, dataRead); }
while (!(dataRead < BufferSize)); rs.Close(); } }
catch (Exception ex) { } finally { fs.Close(); } }
ftp = null; //设置FTP命令
ftp = GetRequest(URI, username, password);
ftp.Method = System.Net.WebRequestMethods.Ftp.Rename; //改名
ftp.RenameTo = fileinfo.Name; try { ftp.GetResponse(); }
catch (Exception ex)
{
ftp = GetRequest(URI, username, password); ftp.Method = System.Net.WebRequestMethods.Ftp.DeleteFile; //删除
ftp.GetResponse(); throw ex; } finally
{
//fileinfo.Delete(); } // 可以记录一个日志 "上传" + fileinfo.FullName + "上传到" + "FTP://" + hostname + "/" + targetDir + "/" + fileinfo.Name + "成功." );
ftp = null;
#region
/***** *FtpWebResponse * ****/ //FtpWebResponse ftpWebResponse = (FtpWebResponse)ftp.GetResponse();
#endregion
}
/// <summary>
/// 下载文件
/// </summary>
/// <param name="localDir">下载至本地路径</param>
/// <param name="FtpDir">ftp目标文件路径</param>
/// <param name="FtpFile">从ftp要下载的文件名</param>
/// <param name="hostname">ftp地址即IP</param>
/// <param name="username">ftp用户名</param>
/// <param name="password">ftp密码</param>
public static void DownloadFile(string localDir, string FtpDir, string FtpFile, string hostname, string username, string password)
{
string URI = "FTP://" + hostname + "/" + FtpDir + "/" + FtpFile;
string tmpname = Guid.NewGuid().ToString();
string localfile = localDir + @"\" + tmpname;
System.Net.FtpWebRequest ftp = GetRequest(URI, username, password);
ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile;
ftp.UseBinary = true;
ftp.UsePassive = false;
using (FtpWebResponse response = (FtpWebResponse)ftp.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
//loop to read & write to file
using (FileStream fs = new FileStream(localfile, FileMode.CreateNew))
{
try
{
byte[] buffer = new byte[2048];
int read = 0;
do
{
read = responseStream.Read(buffer, 0, buffer.Length);
fs.Write(buffer, 0, read);
} while (!(read == 0));
responseStream.Close();
fs.Flush();
fs.Close();
}
catch (Exception)
{
//catch error and delete file only partially downloaded
fs.Close();
//delete target file as it's incomplete
File.Delete(localfile);
throw;
}
}
responseStream.Close();
}
response.Close();
}
try
{
File.Delete(localDir + @"\" + FtpFile);
File.Move(localfile, localDir + @"\" + FtpFile);
ftp = null;
ftp = GetRequest(URI, username, password);
ftp.Method = System.Net.WebRequestMethods.Ftp.DeleteFile;
ftp.GetResponse();
}
catch (Exception ex)
{
File.Delete(localfile);
throw ex;
}
// 记录日志 "从" + URI.ToString() + "下载到" + localDir + @"\" + FtpFile + "成功." );
ftp = null;
}
/// <summary>
/// 搜索远程文件
/// </summary>
/// <param name="targetDir"></param>
/// <param name="hostname"></param>
/// <param name="username"></param>
/// <param name="password"></param>
/// <param name="SearchPattern"></param>
/// <returns></returns>
public static List<string> ListDirectory(string targetDir, string hostname, string username, string password, string SearchPattern)
{
List<string> result = new List<string>();
try
{
string URI = "FTP://" + hostname + "/" + targetDir + "/" + SearchPattern;
System.Net.FtpWebRequest ftp = GetRequest(URI, username, password);
ftp.Method = System.Net.WebRequestMethods.Ftp.ListDirectory;
ftp.UsePassive = true;
ftp.UseBinary = true;
string str = GetStringResponse(ftp);
str = str.Replace("\r\n", "\r").TrimEnd('\r');
str = str.Replace("\n", "\r");
if (str != string.Empty)
result.AddRange(str.Split('\r'));
return result;
}
catch { }
return null;
}
private static string GetStringResponse(FtpWebRequest ftp)
{
//Get the result, streaming to a string
string result = "";
using (FtpWebResponse response = (FtpWebResponse)ftp.GetResponse())
{
long size = response.ContentLength;
using (Stream datastream = response.GetResponseStream())
{
using (StreamReader sr = new StreamReader(datastream, System.Text.Encoding.Default))
{
result = sr.ReadToEnd();
sr.Close();
}
datastream.Close();
}
response.Close();
}
return result;
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
/// <summary>
/// 向Ftp服务器上传文件并创建和本地相同的目录结构
/// 遍历目录和子目录的文件
/// </summary>
/// <param name="file"></param>
private void GetFileSystemInfos(FileSystemInfo file)
{
string getDirecName=file.Name;
if (!ftpIsExistsFile(getDirecName, "192.168.0.172", "Anonymous", "") && file.Name.Equals(FileName))
{
MakeDir(getDirecName, "192.168.0.172", "Anonymous", "");
}
if (!file.Exists) return;
DirectoryInfo dire = file as DirectoryInfo;
if (dire == null) return;
FileSystemInfo[] files = dire.GetFileSystemInfos();
for (int i = 0; i < files.Length; i++)
{
FileInfo fi = files[i] as FileInfo;
if (fi != null)
{
DirectoryInfo DirecObj=fi.Directory;
string DireObjName = DirecObj.Name;
if (FileName.Equals(DireObjName))
{
UploadFile(fi, DireObjName, "192.168.0.172", "Anonymous", "");
}
else
{
Match m = Regex.Match(files[i].FullName, FileName + "+.*" + DireObjName);
//UploadFile(fi, FileName+"/"+DireObjName, "192.168.0.172", "Anonymous", "");
UploadFile(fi, m.ToString(), "192.168.0.172", "Anonymous", "");
}
}
else
{
string[] ArrayStr = files[i].FullName.Split('\\');
string finame=files[i].Name;
Match m=Regex.Match(files[i].FullName,FileName+"+.*"+finame);
//MakeDir(ArrayStr[ArrayStr.Length - 2].ToString() + "/" + finame, "192.168.0.172", "Anonymous", "");
MakeDir(m.ToString(), "192.168.0.172", "Anonymous", "");
GetFileSystemInfos(files[i]);
}
}
}
/// <summary>
/// 判断ftp服务器上该目录是否存在
/// </summary>
/// <param name="dirName"></param>
/// <param name="ftpHostIP"></param>
/// <param name="username"></param>
/// <param name="password"></param>
/// <returns></returns>
private bool ftpIsExistsFile(string dirName, string ftpHostIP, string username, string password)
{
bool flag = true;
try
{
string uri = "ftp://" + ftpHostIP + "/" + dirName;
System.Net.FtpWebRequest ftp = GetRequest(uri, username, password);
ftp.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebResponse response = (FtpWebResponse)ftp.GetResponse();
response.Close();
}
catch (Exception )
{
flag = false;
}
return flag;
}
‘肆’ 怎么用FTP把文件上传到服务器
使用服务器的 ip地址和账号信息,用ftp软件就可以用来上传文件了。
和别人共用服务器时采用的方法。可以把对方的权限限制到某个文件夹里面,他只能在这里上传下载文件,对于服务器安全、权限都有保障。
‘伍’ java如何实现将FTP文件转移到另一个FTP服务器上
你有FTPClient就比较好办,假如你的两台FTP服务器分别为fs1和fs2
在本地开发代码思路如下:
通过FTPClient连接上fs1,然后下载(可以循环批量下载)到本地服务器,保存到一个临时目录。
下载完成后,FTPClient断开与fs1的连接,记得必须logout。
本地服务器通过FileInputStream将刚下载到临时目录的文件读进来,得到一个List<File>集合。
通过FTPClient连接上fs2,循环List<File>集合,将文件上传至fs2的特定目录,然后清空临时目录,上传完毕后,断开fs2的连接,同样必须logout。
‘陆’ 如何将数据转移至新的服务器
1. 先登陆旧服务器上的LUM,在“清理垃圾”中将mysql和postgres的日志清除干净2. 将/home/ftp, /home/mysql_data, /home/pgsql_data, /home/lum_safe_files目录打包,文件名为my_data.tar.gz(如果有多个FTP主目录,需要将所有FTP主目录都打包):cd /home; tar -zcvf my_data.tar.gz ftp mysql_data pgsql_data lum_safe_files3. 在新服务器上安装好LuManager,但需要注意的一点就是,新服务器的上数据库版本需要与旧版本的一致,如旧版本的mysql版本为5.1.59,新服务器上的mysql也必须是5.1,可以是5.1.59,也可以是5.1.61,但不要使用mysql5.5.X4. 在新服务器上执行lu-stop,停止lu服务5. 将新服务器上的/home/ftp, /home/mysql_data, /home/pgsql_data, /home/lum_safe_files目录重命名mv /home/ftp /home/ftp.oldmv /home/mysql_data /home/mysql_data.oldmv /home/pgsql_data /home/pgsql_data.oldmv /home/lum_safe_files /home/lum_safe_files.old6. 将旧服务器上的备份文件my_data.tar.gz转移到新服务器上的/home目录下,然后解压tar -zxvf my_data.tar.gz7. 在新服务器上执行lu-start,启动lu服务,然后再用旧服务器上的帐号登陆LUM便可
‘柒’ 如何把建立在自己电脑上的ftp服务器转移到另一台电脑
在你对应的
/etc/vsftpd/vsftpd_user_conf 目录下 ,把对应账号的
local_root=/home/exchangeftp/edmp/ftpdata/34400001
local_root这个路径改成另一个服务器的 。
‘捌’ 如何从一个ftp的文件转移到另一个ftp
只能重新上传了。你是想迁移ftp服务器吗?用爱米云共享网盘的,迁移服务器非常方便,功能完全可以代替ftp,比ftp还好用
‘玖’ 如何直接把数据从一个ftp服务器上直接复制到另一个ftp服务器上,而不需要先下载然后上传
用Flashfxp这个软件,可以同时开启2个FTP网站,你就可以将数据从这个转到那一个上面去,不过前提是你自己机器上这个程序不能关。
‘拾’ 怎样FTP 把a服务器空间转到B服务器空间
建议你用8UFTP,这个软件是国产简体中文版的,免费的。目前FTP工具市场上体积相对最小。涵盖其它FTP工具功能,支持多线程上传,同时支持直接上传压缩包,可在空间上直接压缩上传,也可上传后在空间上直接解压。
8UFTP工具包括8UFTP客户端工具和8UFTP智能扩展服务器端工具。
1、同时安装8UFTP客户端和8UFTP智能扩展服务器端工具,结合实现在线解压缩功能。
2、8UFTP客户支持目前市场上所有FTP服务端
3、8UFTP智能扩展服务器端配合客户端工具实现在线解压缩功能,当前仅支持Serv-U。