|
注:以下示例只是各个功能的主要程序片段,完整的示例程序请下载"试用版"控件,在试用版程序中有完整的示例源程序;
|
|
|
|
|
|
Visual
Basic 示例:返回顶部
|
|
|
连接FTP服务器:
FtpLibrary1.ServerName ="host name or ip"
FtpLibrary1.UserName ="username"
FtpLibrary1.PassWord ="password"
FtpLibrary1.RemotePort ="21"
If FtpLibrary1.Connect Then
'Success
Else
Msgbox FtpLibrary1.ErrorInfo & "(" & FtpLibrary1.ErrorNumber & ")"
End If
|
上传文件:
FtpLibrary1.LocalPath ="c:\filename.txt"
FtpLibrary1.RemotePath ="filename.txt"
If FtpLibrary1.UpLoad Then
'Success
Else
Msgbox FtpLibrary1.ErrorInfo & "(" & FtpLibrary1.ErrorNumber & ")"
End If
|
上传目录: '最后一个字符必须为'\'
FtpLibrary1.LocalPath ="c:\folder\"
FtpLibrary1.RemotePath ="folder\"
If FtpLibrary1.UpLoad Then
'Success
Else
Msgbox FtpLibrary1.ErrorInfo & "(" & FtpLibrary1.ErrorNumber & ")"
End If
|
上传多个文件和目录: '多个文件以'|'分隔;
FtpLibrary1.LocalPath ="c:\file.txt|c:\file1.txt|c:\folder\"
FtpLibrary1.RemotePath ="folder\"
If FtpLibrary1.UpLoad Then
'Success
Else
Msgbox FtpLibrary1.ErrorInfo & "(" & FtpLibrary1.ErrorNumber & ")"
End If
|
下载文件: 返回顶部
FtpLibrary1.RemotePath ="file.txt"
FtpLibrary1.LocalPath ="c:\file.txt"
If FtpLibrary1.DownLoad Then
'Success
Else
Msgbox FtpLibrary1.ErrorInfo & "(" & FtpLibrary1.ErrorNumber & ")"
End If
|
下载目录: '最后一个字符必须为'\'
FtpLibrary1.RemotePath ="folder\"
FtpLibrary1.LocalPath ="c:\folder\"
If FtpLibrary1.DownLoad Then
'Success
Else
Msgbox FtpLibrary1.ErrorInfo & "(" & FtpLibrary1.ErrorNumber & ")"
End If
|
下载多个文件或目录:
FtpLibrary1.RemotePath ="file.txt|file1.txt|folder\"
FtpLibrary1.LocalPath ="c:\folder\"
If FtpLibrary1.DownLoad Then
'Success
Else
Msgbox FtpLibrary1.ErrorInfo & "(" & FtpLibrary1.ErrorNumber & ")"
End If
|
显示传输进度:
Private Sub FtpLibrary1_OnTransfer()
Debug.Print FtpLibrary1.Percent & "%(" & FtpLibrary1.FileSize & "/" & FtpLibrary1.TransferSize & ")"
Debug.Print FtpLibrary1.FormatFileSize(FtpLibrary1.Speed) & "/s"
Debug.Print FtpLibrary1.FormatTime(FtpLibrary1.LeftTime)
End Sub
|
获取文件大小和时间:
Dim objFile As CFtpFile
Set objFile = FtpLibrary1.GetFtpFileInfo("file.txt")
If objFile Is Nothing Then
If FtpLibrary1.ErrorNumber <> 0 Then
MsgBox FtpLibrary1.ErrorInfo
Else
MsgBox "test.txt not exist"
End If
Else
MsgBox objFile.FileName & "|" & FtpLibrary.FormatFileSize(objFile.FileSize)
& "|" & objFile.LastWriteTime
End If
|
获取目录列表:返回顶部
Dim objFiles As CFtpFiles
Dim i As Long
Dim strFileInfo As String
strFileInfo = ""
Set objFiles = FtpLibrary1.GetFtpDirectoryInfo("folder")
If objFiles Is Nothing Then
If FtpLibrary1.ErrorNumber <> 0 Then
MsgBox FtpLibrary1.ErrorInfo
Else
MsgBox "Empty Directory. " & txtRemotePath.Text
End If
Else
For i = 1 To objFiles.count
If objFiles.Item(i).IsDirectory Then
strFileInfo = strFileInfo & i & ".Folder: "
Else
strFileInfo = strFileInfo & i & ".File : "
End If
strFileInfo = strFileInfo & objFiles.Item(i).FileName
If objFiles.Item(i).IsDirectory Then
strFileInfo = strFileInfo & " (" & objFiles.Item(i).LastWriteTime & ")" & vbCrLf
Else
strFileInfo = strFileInfo & " (" & FtpLibrary1.FormatFileSize(objFiles.Item(i).FileSize)
& "," & objFiles.Item(i).LastWriteTime & ")" & vbCrLf
End If
Next
If Len(strFileInfo) > 500 Then
strFileInfo = Left(strFileInfo, 500)
strFileInfo = Left(strFileInfo, InStrRev(strFileInfo, vbCrLf)) & vbCrLf & "......"
End If
MsgBox "The number of files/folders:" & objFiles.count & vbCrLf & strFileInfo
End If
|
|
返回顶部
|
|
Powerbuilder
示例:返回顶部
|
|
|
连接FTP服务器:
ole_ftp.object.servername="server name or ip"
ole_ftp.object.username="username"
ole_ftp.object.password="password"
ole_ftp.object.remoteport="21"
if ole_ftp.object.connect() then
//Connected
else
Messagebox("Easewe software",String(ole_ftp.object.ErrorInfo))
end if
|
上传文件:
ole_ftp.object.localpath="c:\file.txt"
ole_ftp.object.remotepath="file.txt"
if ole_ftp.object.upload() then
messagebox("Easewe software","Finished")
else
messagebox("Easewe software",string(ole_ftp.object.errorinfo))
end if
|
上传目录 '最后一个字符必须为'\'
ole_ftp.object.localpath="c:\folder\"
ole_ftp.object.remotepath="folder\"
if ole_ftp.object.upload() then
messagebox("Easewe software","Finished")
else
messagebox("Easewe software",string(ole_ftp.object.errorinfo))
end if
|
上传多个文件或目录: '多个文件以'|'分隔;
ole_ftp.object.localpath="c:\file.txt|c:\folder\"
ole_ftp.object.remotepath="folder\"
if ole_ftp.object.upload() then
messagebox("Easewe software","Finished")
else
messagebox("Easewe software",string(ole_ftp.object.errorinfo))
end if
|
下载文件: 返回顶部
ole_ftp.object.localpath="c:\file.txt"
ole_ftp.object.remotepath="file.txt"
if ole_ftp.object.download() then
messagebox("Easewe software","Finished")
else
messagebox("Easewe software",string(ole_ftp.object.errorinfo))
end if
|
下载目录: '最后一个字符必须为'\'
ole_ftp.object.localpath="c:\folder\"
ole_ftp.object.remotepath="folder\"
if ole_ftp.object.download() then
messagebox("Easewe software","Finished")
else
messagebox("Easewe software",string(ole_ftp.object.errorinfo))
end if
|
下载多个文件或目录:
ole_ftp.object.localpath="c:\folder\"
ole_ftp.object.remotepath="file.txt|folder\"
if ole_ftp.object.download() then
messagebox("Easewe software","Finished")
else
messagebox("Easewe software",string(ole_ftp.object.errorinfo))
end if
|
显示传输进度:
//--copy to ontransfer event of object ole_ftp:
hpb_progress.position=ole_ftp.object.percent
st_speed.text=ole_ftp.object.formatfilesize(ole_ftp.object.speed) + "/s"
st_remainingtime.text=ole_ftp.object.formattime(ole_ftp.object.lefttime)
|
获取文件大小和时间:
oleobject ole_ftpfile
ole_ftpfile= create oleobject
ole_ftpfile.ConnectToNewObject("EaseWeFtp.CFtpFile")
ole_ftpfile=ole_ftp.object.GetFtpFileInfo("file.txt")
if isnull(ole_ftpfile) then
messagebox("Easewe software","Failed~n" + string(ole_ftp.object.errorinfo))
else
messagebox("Easewe software",string(ole_ftpfile.filename)+ "~t"
+ string(ole_ftp.object.formatfilesize(ole_ftpfile.filesize))
+"~t" +string(ole_ftpfile.LastWriteTime))
end if
|
获取目录列表:返回顶部
//--
oleobject ole_ftpfiles
ole_ftpfiles= create oleobject
ole_ftpfiles.ConnectToNewObject("EaseWeFtp.CFtpFiles")
ole_ftpfiles=ole_ftp.object.GetFtpDirectoryInfo("folder")
if isnull(ole_ftpfiles) then
if(ole_ftp.object.errornumber=0) then
messagebox("Easewe software","Empty Directory: " + sle_remotepath.text)
else
messagebox("Easewe software","Failed~n" + string(ole_ftp.object.errorinfo ) )
end if
else
string filelists
int i
for i=1 to ole_ftpfiles.count
if ole_ftpfiles.item[i].IsDirectory then
filelists+="Folder:"
else
filelists+="File :"
end if
filelists+=string(ole_ftpfiles.item[i].filename)+ " ("
+ string(ole_ftp.object.formatfilesize(ole_ftpfiles.item[i].filesize))
+" # " +string(ole_ftpfiles.item[i].LastWriteTime + ")")
filelists+="~n"
next
messagebox("Easewe software",filelists)
end if
|
|
返回顶部
|
|
Javascript
示例:返回顶部
|
|
|
连接FTP服务器:
FtpLibrary.ServerName = "server name or ip";
FtpLibrary.UserName = "username";
FtpLibrary.PassWord = "password";
FtpLibrary.RemotePort = "21";
if(FtpLibrary.Connect()){
//Connected
}else{
alert("Failed to connect to server:\n" + FtpLibrary.ErrorInfo);
}
|
上传文件:
FtpLibrary.LocalPath = "c:\file.txt";
FtpLibrary.RemotePath = "file.txt";
if ( FtpLibrary.UpLoad() ){
alert("Finish!");
}else{
if(FtpLibrary.ErrorNumber!=16010){
alert("Failure!\n" + FtpLibrary.ErrorInfo);
}else{
alert(FtpLibrary.ErrorInfo);
}
}
|
上传目录 '最后一个字符必须为'\'
FtpLibrary.LocalPath = "c:\folder\";
FtpLibrary.RemotePath = "folder\";
if ( FtpLibrary.UpLoad() ){
alert("Finish!");
}else{
if(FtpLibrary.ErrorNumber!=16010){
alert("Failure!\n" + FtpLibrary.ErrorInfo);
}else{
alert(FtpLibrary.ErrorInfo);
}
}
|
上传多个文件或目录: '多个文件以'|'分隔;
FtpLibrary.LocalPath = "c:\file.txt|c:\folder\";
FtpLibrary.RemotePath = "folder\";
if ( FtpLibrary.UpLoad() ){
alert("Finish!");
}else{
if(FtpLibrary.ErrorNumber!=16010){
alert("Failure!\n" + FtpLibrary.ErrorInfo);
}else{
alert(FtpLibrary.ErrorInfo);
}
}
|
下载文件: 返回顶部
FtpLibrary.LocalPath = "c:\file.txt";
FtpLibrary.RemotePath = "file.txt";
if ( FtpLibrary.DownLoad() ){
alert("Finish!");
}else{
if(FtpLibrary.ErrorNumber!=16010){
alert("Failure!\n" + FtpLibrary.ErrorInfo);
}else{
alert(FtpLibrary.ErrorInfo);
}
}
|
下载目录: '最后一个字符必须为'\'
FtpLibrary.LocalPath = "c:\folder\";
FtpLibrary.RemotePath = "folder\";
if ( FtpLibrary.DownLoad() ){
alert("Finish!");
}else{
if(FtpLibrary.ErrorNumber!=16010){
alert("Failure!\n" + FtpLibrary.ErrorInfo);
}else{
alert(FtpLibrary.ErrorInfo);
}
}
|
下载多个文件或目录:
FtpLibrary.LocalPath = "c:\folder\";
FtpLibrary.RemotePath = "file.txt|folder\";
if ( FtpLibrary.DownLoad() ){
alert("Finish!");
}else{
if(FtpLibrary.ErrorNumber!=16010){
alert("Failure!\n" + FtpLibrary.ErrorInfo);
}else{
alert(FtpLibrary.ErrorInfo);
}
}
|
显示传输进度:
//--copy to event OnTransfer of FtpLibrary
var percent = FtpLibrary.Percent;
var speed = FtpLibrary.FormatFileSize(FtpLibrary.Speed)+"/s";
var remainingtime = FtpLibrary.FormatTime(FtpLibrary.LeftTime);
|
获取文件大小和时间:
var aryFile=FtpLibrary.GetFtpFileInfo("file.txt");
if(aryFile){
alert(aryFile.FileName + "|" + FtpLibrary.FormatFileSize(aryFile.FileSize)
+ "|" + aryFile.LastWriteTime);
}else{
if(FtpLibrary.ErrorNumber==0){
alert("File Not Exist!");
}else{
alert(FtpLibrary.ErrorInfo);
}
}
|
获取目录列表:返回顶部
var aryFiles=FtpLibrary.GetFtpDirectoryInfo("folder");
if(aryFiles){
var fileCount=aryFiles.Count;
var fileInfo="The number of files:"+fileCount+"\n";
for(var i=1;i<=fileCount;i++){
if(aryFiles.Item(i).IsDirectory){
fileInfo+="Folder"+i+":";
}else{
fileInfo+="File"+i+" :";
}
fileInfo+=aryFiles.Item(i).FileName;
if(!aryFiles.Item(i).IsDirectory){
fileInfo+=" # "+FtpLibrary.FormatFileSize(aryFiles.Item(i).FileSize);
fileInfo+=" # "+aryFiles.Item(i).LastWriteTime
}
fileInfo+="\n";
}
alert(fileInfo);
}else{
if(FtpLibrary.ErrorNumber==0){
alert("Empty directory!");
}else{
alert(FtpLibrary.ErrorInfo);
}
}
|
|
返回顶部
|
|
Delphi
示例:返回顶部
|
|
|
连接FTP服务器:
FtpLibrary1.ServerName:='server name or ip';
FtpLibrary1.UserName:='username';
FtpLibrary1.PassWord:='password';
FtpLibrary1.RemotePort:=21;
if(FtpLibrary1.Connect())then
//Application.MessageBox('Connected','EaseWe Software')
else
Application.MessageBox(pchar('Faild'+#13+string(FtpLibrary1.ErrorInfo)), 'EaseWe Software');
|
上传文件:
FtpLibrary1.localpath:='c:\file.txt';
FtpLibrary1.remotepath:='file.txt';
if FtpLibrary1.upload(True) then
application.messagebox('Finish','Easewe software')
else
application.messagebox(pchar(string(FtpLibrary1.errorinfo)),'Easewe software') ;
|
上传目录 '最后一个字符必须为'\'
FtpLibrary1.localpath:='c:\folder\' ;
FtpLibrary1.remotepath:='folder\';
if FtpLibrary1.upload(True) then
application.messagebox('Finish','Easewe software')
else
application.messagebox(pchar(string(FtpLibrary1.errorinfo)),'Easewe software') ;
|
上传多个文件或目录: '多个文件以'|'分隔;
FtpLibrary1.localpath:='c:\file.txt|folder\' ;
FtpLibrary1.remotepath:='folder\';
if FtpLibrary1.upload(True) then
application.messagebox('Finish','Easewe software')
else
application.messagebox(pchar(string(FtpLibrary1.errorinfo)),'Easewe software') ;
|
下载文件: 返回顶部
FtpLibrary1.localpath:='c:\file.txt' ;
FtpLibrary1.remotepath:='file.txt';
if FtpLibrary1.download(True) then
application.messagebox('Finish','Easewe software')
else
application.messagebox(pchar(string(FtpLibrary1.errorinfo)),'Easewe software') ;
|
下载目录: '最后一个字符必须为'\'
FtpLibrary1.localpath:='c:\folder' ;
FtpLibrary1.remotepath:='folder\';
if FtpLibrary1.download(True) then
application.messagebox('Finish','Easewe software')
else
application.messagebox(pchar(string(FtpLibrary1.errorinfo)),'Easewe software') ;
|
下载多个文件或目录:
FtpLibrary1.localpath:='c:\folder\' ;
FtpLibrary1.remotepath:='file.txt|folder\';
if FtpLibrary1.download(True) then
application.messagebox('Finish','Easewe software')
else
application.messagebox(pchar(string(FtpLibrary1.errorinfo)),'Easewe software') ;
|
显示传输进度:
procedure TForm1.FtpLibrary1Transfer(Sender: TObject);
var speed:double;
var seconds:integer;
var timetype:Smallint;
begin
speed:=FtpLibrary1.speed;
seconds:= FtpLibrary1.lefttime;
timetype:=0;
ProgressBar1.position:=FtpLibrary1.percent;
lblSpeed.Caption:=FtpLibrary1.formatfilesize(speed) + '/s';
lblRemainingTime.Caption:=FtpLibrary1.formattime(seconds,timetype);
end;
|
获取文件大小和时间:
procedure TForm1.btnGetFileInfoClick(Sender: TObject);
var ftpfile:CFtpFile;
var filelists:string;
var filesize:double;
begin
ftpfile:=FtpLibrary1.GetFtpFileInfo('file.txt') ;
if ftpfile = nil then
application.messagebox(pchar('Failed'+#13+string(FtpLibrary1.errorinfo )) ,'Easewe software')
else
begin
filesize:=ftpfile.filesize;
filelists:=filelists+string(ftpfile.filename)+ ' (';
filelists:=filelists+string(FtpLibrary1.formatfilesize(filesize)) +' # ';
filelists:=filelists+string(ftpfile.LastWriteTime + ')') ;
application.messagebox(pchar(string(filelists)),'Easewe software');
end;
end;
|
获取目录列表:返回顶部
procedure TForm1.btnGetFileListClick(Sender: TObject);
var ftpfiles:CFtpFiles;
var filelists:string;
var i:integer;
var filesize:double;
begin
ftpfiles:=FtpLibrary1.GetFtpDirectoryInfo('folder') ;
if ftpfiles = nil then
if(FtpLibrary1.errornumber=0) then
application.messagebox(pchar('Empty Directory: '
+ string('folder')),'Easewe software')
else
application.messagebox(pchar('Failed'+#13
+ string(FtpLibrary1.errorinfo )) ,'Easewe software' )
else
begin
for i:=1 to ftpfiles.count do
begin
if ftpfiles.item[i].IsDirectory then
filelists:=filelists+'Folder:'
else
filelists:=filelists+'File :';
filesize:=ftpfiles.item[i].filesize;
filelists:=filelists+string(ftpfiles.item[i].filename)+ ' (';
filelists:=filelists+string(FtpLibrary1.formatfilesize(filesize)) +' # ';
filelists:=filelists+string(ftpfiles.item[i].LastWriteTime + ')') ;
filelists:=filelists+#13;
end;
application.messagebox(pchar(string(filelists)),'Easewe software');
end;
end;
|
|
返回顶部
|
|
C#.Net
示例:返回顶部
|
|
|
连接FTP服务器:
axFtpLibrary1.ServerName = "server name or ip";
axFtpLibrary1.UserName = "username";
axFtpLibrary1.PassWord = "password";
axFtpLibrary1.RemotePort = Convert.ToInt32("21");
if (axFtpLibrary1.Connect())
{
//Connected
}
else
{
MessageBox.Show("Connect failed\n" + axFtpLibrary1.ErrorInfo);
}
|
上传文件:
axFtpLibrary1.RemotePath = "file.txt";
axFtpLibrary1.LocalPath = "c:\file.txt";
if (axFtpLibrary1.UpLoad())
{
MessageBox.Show("Finished");
}
else
{
MessageBox.Show("Failed\n" + axFtpLibrary1.ErrorInfo);
}
|
上传目录 '最后一个字符必须为'\'
axFtpLibrary1.RemotePath = "folder\";
axFtpLibrary1.LocalPath = "c:\folder\";
if (axFtpLibrary1.UpLoad())
{
MessageBox.Show("Finished");
}
else
{
MessageBox.Show("Failed\n" + axFtpLibrary1.ErrorInfo);
}
|
上传多个文件或目录: '多个文件以'|'分隔;
axFtpLibrary1.RemotePath = "folder\";
axFtpLibrary1.LocalPath = "c:\file.txt|c:\folder\";
if (axFtpLibrary1.UpLoad())
{
MessageBox.Show("Finished");
}
else
{
MessageBox.Show("Failed\n" + axFtpLibrary1.ErrorInfo);
}
|
下载文件: 返回顶部
axFtpLibrary1.RemotePath = "file.txt";
axFtpLibrary1.LocalPath = "c:\file.txt";
if (axFtpLibrary1.DownLoad())
{
MessageBox.Show("Finished");
}
else
{
MessageBox.Show("Failed\n" + axFtpLibrary1.ErrorInfo);
}
|
下载目录: '最后一个字符必须为'\'
axFtpLibrary1.RemotePath = "folder\";
axFtpLibrary1.LocalPath = "c:\folder\";
if (axFtpLibrary1.DownLoad())
{
MessageBox.Show("Finished");
}
else
{
MessageBox.Show("Failed\n" + axFtpLibrary1.ErrorInfo);
}
|
下载多个文件或目录:
axFtpLibrary1.RemotePath = "file.txt|folder\";
axFtpLibrary1.LocalPath = "c:\folder\";
if (axFtpLibrary1.DownLoad())
{
MessageBox.Show("Finished");
}
else
{
MessageBox.Show("Failed\n" + axFtpLibrary1.ErrorInfo);
}
|
显示传输进度:
private void axFtpLibrary1_OnTransfer(object sender, EventArgs e)
{
double speed=axFtpLibrary1.Speed;
lblSpeed.Text = axFtpLibrary1.FormatFileSize(speed) + "/s";
lblPercent.Text = axFtpLibrary1.get_Percent().ToString() + "%";
}
|
获取文件大小和时间:
EaseWeFtp.CFtpFile file = axFtpLibrary1.GetFtpFileInfo("file.txt");
//--
if (file != null)
{
double fileSize = file.FileSize;
MessageBox.Show(file.FileName + "|" + axFtpLibrary1.FormatFileSize(fileSize)
+ "|" + file.LastWriteTime);
}
else
{
if (axFtpLibrary1.ErrorNumber == 0)
{
MessageBox.Show("File not exist!");
}
else
{
MessageBox.Show(axFtpLibrary1.ErrorInfo);
}
}
|
获取目录列表:返回顶部
EaseWeFtp.CFtpFiles files = axFtpLibrary1.GetFtpDirectoryInfo("file.txt");
//--
if (files != null)
{
string listing = "";
double fileSize = 0;
for (short i = 1; i <= files.Count; i++)
{
fileSize = (double)files.get_Item(i).FileSize;
if (files.get_Item(i).IsDirectory)
{
listing += "Folder:" + files.get_Item(i).FileName
+ " <" + files.get_Item(i).LastWriteTime + ">\n";
}
else
{
listing += files.get_Item(i).FileName + " <"
+ axFtpLibrary1.FormatFileSize(fileSize) + " , "
+ files.get_Item(i).LastWriteTime + ">\n";
}
}
MessageBox.Show(listing);
}
else
{
if (axFtpLibrary1.ErrorNumber == 0)
{
MessageBox.Show("Nothing in " + txtRemote.Text);
}
else
{
MessageBox.Show(axFtpLibrary1.ErrorInfo);
}
}
|
|
返回顶部
|
|