go语言获取ftp文件 golang ftp client

如何用FTP获取文件如果是通过命令行交互式go语言获取ftp文件的:
1.
ftp
server_ip
2.
提示输入用户名:输入go语言获取ftp文件你go语言获取ftp文件的ftp用户名
3.
提示输入密码:输入ftp用户的密码
4.
切换为bin模式:b或者bin命令
5.
用get命令接完整文件名:get
your_file
6.
用wget 通配符模式获取多个文件:wget
*.txt
7.
退出ftp:bye
易语言如何获取FTP服务器文件列表,并显示到列表框 , 有知道的回答下,问了全世界都没人知道文件号 = 写到文件 (取运行目录 () + “自己取名字”, HTTP读文件 (“自己的FTP列表”))
循环判断首 ()
列表框1.加入项目 (读入一行 (文件号), )
循环判断尾 (是否在文件尾 (文件号, ) = 假)
C# 获取Ftp某个目录下的所有文件(不要文件夹)我在之前做过一个FTP的客户端工具 。
drw文件夹
-rw文件(有扩展名或无扩展名)
我是根据服务端返回的报文进行分析获取的列表 。
给你一些代码片段:
/// summary
/// 获取指定目录下的文件和文件夹 。
/// /summary
/// param name="path"要获取的目录/param
/// param name="WRMethods"要发送到FTP服务器的密令 。/param
/// returns/returns
public string[] GetFileList(string path, string WRMethods)//从ftp服务器上获得文件列表
{
WebResponse response;
string[] downloadFiles;
int conut = 4;
StringBuilder result = new StringBuilder();
Connect(path);
if (FTPVariable.IsUseProxy_ftp)
{
req = FtpProxy.GetFtpSelectProxy(FTPVariable.FtpCommand_transferProxyName);
}
req = 12000;
//如果不应销毁到服务器的连接,则为 true;否则为 false 。默认值为 true 。
//
req = WRMethods;
try
{
response = (FtpWebResponse)req;
goto Ftp_lbl_03;
}
catch (WebException webex)
{
GetReply(webex.Message);
if (ReplyCode == 530)// 未登录 。
{
goto Ftp_lbl_04;
}
else if (ReplyCode == 550)
{
goto Ftp_lbl_04;
}
else
{
FtpManage.SetLog("获取列表超时,等候1秒后重试!");
goto Ftp_lbl_01;
}
}
Ftp_lbl_01:
try
{
FtpManage.SetLog("正在连接服务器 "FtpRemoteHost);
response = GetRequest(path, WRMethods);
}
catch (WebException)
{
FtpManage.SetLog("获取列表超时,等候1秒后重试!");
downloadFiles = null;
System.Threading.Thread.Sleep(1000);
if (conut == 0)
{
goto Ftp_lbl_02;
}
conut--;
goto Ftp_lbl_01;
}
catch (Exception ex)
{
MSG.Show(ex.Message, Global.GetRS["msgTilteError"], MessageBoxButton.OK, MsgIco.Error);
FtpManage.SetLog("命令执行失败,原因:"ex.Message);
downloadFiles = null;
return downloadFiles;
}
Ftp_lbl_03:
StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);//中文文件名
string line = reader.ReadLine();
while (line != null)
{
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
}
if (result.Length == 0)
{
return null;
}
// to remove the trailing '\n'
result.Remove(result.ToString().LastIndexOf('\n'), 1);
reader.Close();
response.Close();
FtpManage.SetLog("命令已成功执行");
【go语言获取ftp文件 golang ftp client】return result.ToString().Split('\n');
Ftp_lbl_04:
FtpManage.SetLog(ReplyInfo);
return null;
Ftp_lbl_02:
FtpManage.SetLog("550 获取列表失败,无法连接远程服务器!");
FtpManage.ftpmanage.IsRefurbish = true;
return null;
}
/// summary
/// 获取指定目录下的文件和文件夹 。
/// /summary
/// param name="path"要获取的目录/param
/// returns/returns
public string[] GetFileList(string path)//从ftp服务器上获得文件列表
{
return GetFileList(FTPVariable.FtpURLheadFtpRemoteHost"/"path, WebRequestMethods.);
}
/// summary
/// 获取指定目录下的文件和文件夹 。
/// /summary
/// returns/returns
public string[] GetFileList()//从ftp服务器上获得文件列表
{
return GetFileList(FTPVariable.FtpURLheadFtpRemoteHost"/", WebRequestMethods.);
}
/// summary
/// 获取目录和文件名,返回目录表 。
/// /summary
/// param name="path"要获取的目录/param
/// returns/returns
public string[] GetCatalog_FileList(string path)
{
string[] fountainhead = GetFileList(FTPVariable.FtpURLheadFtpRemoteHost"/"path, WebRequestMethods.);
string[] Catalog = null;
if (fountainhead == null)
{
return null;
}
Catalog = new string[fountainhead.Length];
for (int i = 3; ifountainhead.Length; i)
{
Catalog[i - 3]= fountainhead[i].Substring(55, fountainhead[i].Length - 55)"";//FileName
Catalog[i - 3]= fountainhead[i].Substring(30, 12)"";//FileSize
Catalog[i - 3]= fountainhead[i].Substring(42, 13)"";//AmendDate
Catalog[i - 3]= fountainhead[i].Substring(0, 3)"";
}
return Catalog;
}
C怎么获取FTP上所有的文件夹?还有所有文件?通过CFtpFileFind递归进行查询go语言获取ftp文件,如果没有文件go语言获取ftp文件,会返回false,就不用进行再查找go语言获取ftp文件了 。如果有文件或文件夹go语言获取ftp文件,通过getnext进行遍历查看就行
file_get_contents() 可以通过ftp获取内容吗? 我想获取通过ftp上的文件 。通常,在 php 里获取ftp 服务器上的文件,使用 ftp_get 及相关的 ftp 函数,以下是示例:
?php
// define some variables
$local_file = 'local.zip';
$server_file = 'server.zip';
// connect to the FTP server
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
echo "Successfully written to $local_file ";
} else {
echo "There was a problem ";
}
// close the connection
ftp_close($conn_id);
?
go语言获取ftp文件的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于golang ftp client、go语言获取ftp文件的信息别忘了在本站进行查找喔 。

    推荐阅读