Visual Basic Samples:Back
to top |
|
Connect to ftp server:
FtpLibrary1.ServerName ="host name or ip"
FtpLibrary1.Username ="Username"
FtpLibrary1.Password ="Password"
FtpLibrary1.Port =21
If FtpLibrary1.Connect Then
'Success
Else
Msgbox FtpLibrary1.ErrorInfo & "(" & FtpLibrary1.ErrorNumber & ")"
End If
|
Upload file:
FtpLibrary1.LocalPath ="c:\filename.txt"
FtpLibrary1.RemotePath ="filename.txt"
If FtpLibrary1.Upload Then
'Success
Else
Msgbox FtpLibrary1.ErrorInfo & "(" & FtpLibrary1.ErrorNumber & ")"
End If
|
Upload directory
'The last character of the path must be '\'
FtpLibrary1.LocalPath ="c:\folder\"
FtpLibrary1.RemotePath ="folder\"
If FtpLibrary1.Upload Then
'Success
Else
Msgbox FtpLibrary1.ErrorInfo & "(" & FtpLibrary1.ErrorNumber & ")"
End If
|
Upload multiple files/directories:
'Each path is separated by '|'
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
|
Download file:
Back
to top
FtpLibrary1.RemotePath ="file.txt"
FtpLibrary1.LocalPath ="c:\file.txt"
If FtpLibrary1.Download Then
'Success
Else
Msgbox FtpLibrary1.ErrorInfo & "(" & FtpLibrary1.ErrorNumber & ")"
End If
|
Download directory:
'The last character of the path must be '\'
FtpLibrary1.RemotePath ="folder\"
FtpLibrary1.LocalPath ="c:\folder\"
If FtpLibrary1.Download Then
'Success
Else
Msgbox FtpLibrary1.ErrorInfo & "(" & FtpLibrary1.ErrorNumber & ")"
End If
|
Download multiple files/directories:
FtpLibrary1.RemotePath ="file.txt|file1.txt|folder\"
FtpLibrary1.LocalPath ="c:\folder\"
If FtpLibrary1.Download Then
'Success
Else
Msgbox FtpLibrary1.ErrorInfo & "(" & FtpLibrary1.ErrorNumber & ")"
End If
|
Show transfer progress:
Private Sub FtpLibrary1_OnTransfer()
Debug.Print FtpLibrary1.Percent & "%(" & FtpLibrary1.TransferredSize & "/" & FtpLibrary1.FileSize & ")"
Debug.Print FtpLibrary1.FormatSize(FtpLibrary1.Speed) & "/s"
Debug.Print FtpLibrary1.FormatTime(FtpLibrary1.LeftTime)
End Sub
|
Get file size and last modified time:
Dim strFileInfo As String
strFileInfo = FtpLibrary1.GetFileInfo("file.txt")
If strFileInfo = "" Then
If FtpLibrary1.ErrorNumber <> 0 Then
MsgBox FtpLibrary1.ErrorInfo
Else
MsgBox "file not found"
End If
Else
Dim aryItem() As String
aryItem = Split(strFileInfo, "*")
strFileInfo = "File name: " & aryItem(0) & vbCrLf & "File size: "
& FtpLibrary1.FormatSize(aryItem(1)) & vbCrLf & "Modified: " & aryItem(2)
MsgBox strFileInfo
End If
|
Get directory listing:Back to top
Dim i As Long
Dim strFiles,fileList As String
Dim aryFile() As String
Dim aryItem() As String
strFiles = FtpLibrary1.GetFileList("folder name")
'--
lstServerFiles.Clear
'--
If strFiles = "" Then
If FtpLibrary1.ErrorNumber <> 0 Then
MsgBox FtpLibrary1.ErrorInfo
Else
Debug.Print i & "|" & "Empty Directory. " & FolderPath
End If
Else
aryFile = Split(strFiles, "|")
'--
For i = 0 To UBound(aryFile)
If Left(aryFile(i), 2) = "1*" Then 'Directory
aryItem = Split(aryFile(i), "*")
'--
fileList = fileList & aryItem(1) & vbCrLf
End If
Next
'--
For i = 0 To UBound(aryFile)
If Left(aryFile(i), 2) = "0*" Then 'File
aryItem = Split(aryFile(i), "*")
'--
fileList = fileList & aryItem(1) & " <"
& FtpLibrary1.FormatSize(aryItem(2)) & "> , <" & aryItem(3) & ">" & vbCrLf
End If
Next
End If
|
Back to top |
Powerbuilder Samples:Back to top |
|
Connect to ftp server:
ole_ftp.object.servername="server name or ip"
ole_ftp.object.Username="Username"
ole_ftp.object.Password="Password"
ole_ftp.object.Port=21
if ole_ftp.object.connect() then
//Connected
else
Messagebox("Easewe software",String(ole_ftp.object.ErrorInfo))
end if
|
Upload file:
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
|
Upload directory
'The last character of the path must be '\'
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
|
Upload multiple files/directories:
'Each path is separated by '|'
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
|
Download file:
Back to top
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
|
Download directory:
'The last character of the path must be '\'
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
|
Download multiple files/directories:
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
|
Show transfer progress:
//--copy to ontransfer event of object ole_ftp:
hpb_progress.position=ole_ftp.object.percent
st_speed.text=ole_ftp.object.formatsize(ole_ftp.object.speed) + "/s"
st_remainingtime.text=ole_ftp.object.formattime(ole_ftp.object.lefttime)
|
Get file size and last modified time:
//----------------------------
global function integer split (string as_string, string as_delimiter, ref string as_aryitem[]);
long i,p,lp
i=1
lp=1
as_string=as_string+as_delimiter
p=pos(as_string,as_delimiter,lp)
do while p> 0
as_aryitem[i]=mid(as_string,lp,p - lp)
lp=p+len(as_delimiter)
p=pos(as_string,as_delimiter,lp )
//--
i++
loop
return i - 1;
end function
//----------------------------
string fileinfo
fileinfo=ole_ftp.object.GetFileInfo("file.txt")
if fileinfo="" then
messagebox("Easewe software","Failed~n" + string(ole_ftp.object.errorinfo ) )
else
string aryitem[];
split(fileinfo,"*",aryitem)
//--
messagebox("Easewe software",string(aryitem[1])+ "~t" +
string(ole_ftp.object.formatsize(double(aryitem[2]))) +"~t" +string(aryitem[3]))
end if
|
Get directory listing:Back to top
//--
string fileinfo
fileinfo=ole_ftp.object.GetFileList("folder name")
if fileinfo="" 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,aryfile[],aryitem[]
int i
//--
split(fileinfo,"|",aryfile)
//--
for i=1 to upperbound(aryfile)
split(aryfile[i],"*",aryitem)
//--
if aryitem[1]="1" then
filelists+="Folder:"
else
filelists+="File :"
end if
filelists+=string(aryitem[2])+ " <" + string(ole_ftp.object.formatsize(double(aryitem[3])))
+" , " +string(aryitem[4] + ">")
filelists+="~n"
next
messagebox("Easewe software",filelists)
end if
|
Back to top |
Javascript Samples:Back
to top |
|
Connect to ftp server:
FtpLibrary.ServerName = "server name or ip";
FtpLibrary.Username = "Username";
FtpLibrary.Password = "Password";
FtpLibrary.Port = 21;
if(FtpLibrary.Connect()){
//Connected
}else{
alert("Failed to connect to server:\n" + FtpLibrary.ErrorInfo);
}
|
Upload file:
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);
}
}
|
Upload directory
'The last character of the path must be '\'
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);
}
}
|
Upload multiple files/directories:
'Each path is separated by '|'
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);
}
}
|
Download file:
Back to top
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);
}
}
|
Download directory:
'The last character of the path must be '\'
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);
}
}
|
Download multiple files/directories:
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);
}
}
|
Show transfer progress:
//--copy to event OnTransfer of FtpLibrary
var percent = FtpLibrary.Percent;
var speed = FtpLibrary.FormatSize(FtpLibrary.Speed)+"/s";
var remainingtime = FtpLibrary.FormatTime(FtpLibrary.LeftTime);
|
Get file size and last modified time:
var fileinfo=FtpLibrary.GetFileInfo("file.txt");
if(fileinfo!=""){
var aryItem = new Array();
aryItem = fileinfo.split("*");
alert(aryItem[0] + "<" + FtpLibrary.FormatSize(aryItem[1]) + "," + aryItem[2] + ">");
}else{
if(FtpLibrary.ErrorNumber==0){
alert("File Not found!");
}else{
alert(FtpLibrary.ErrorInfo);
}
}
|
Get directory listing:Back to top
var filelist = FtpLibrary.GetFileList("folder name");
var aryFiles = new Array(); var aryItem = new Array();
aryFiles = filelist.split("|");
if (aryFiles.length > 0) {
var count = aryFiles.length; var fileCount = 0, folderCount = 0;
var fileInfo = "";
for (var i = 0; i < count; i++) {
if (aryFiles[i].substr(0, 1) == "1") {
folderCount++;
aryItem = aryFiles[i].split("*");
fileInfo += aryItem[1];
fileInfo += "\n";
}
}
for (var i = 0; i < count; i++) {
if (aryFiles[i].substr(0, 1) == "0") {
fileCount++;
aryItem = aryFiles[i].split("*");
fileInfo += aryItem[1];
fileInfo += " <" + FtpLibrary.FormatSize(aryItem[2]);
fileInfo += " , " + aryItem[3] + ">";
fileInfo += "\n";
}
}
//--
if (folderCount > 0 && fileCount > 0) {
fileInfo = folderCount + " folder(s), " + fileCount + " file(s):\n----------------------------\n" + fileInfo;
} else {
if (folderCount > 0) fileInfo = folderCount + " folder(s):\n----------------------------\n" + fileInfo;
if (fileCount > 0) fileInfo = fileCount + " file(s):\n----------------------------\n" + fileInfo;
}
//--
alert(fileInfo);
} else {
if (FtpLibrary.ErrorNumber == 0) {
alert("Empty directory!");
} else {
alert(FtpLibrary.ErrorInfo);
}
}
|
Back to top |
Delphi Samples:Back
to top |
|
Connect to ftp server:
FtpLibrary1.ServerName:='server name or ip';
FtpLibrary1.Username:='Username';
FtpLibrary1.Password:='Password';
FtpLibrary1.Port:=21;
if(FtpLibrary1.Connect())then
//Application.MessageBox('Connected','EaseWe Software')
else
Application.MessageBox(pchar('Faild'+#13+string(FtpLibrary1.ErrorInfo)), 'EaseWe Software');
|
Upload file:
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') ;
|
Upload directory
'The last character of the path must be '\'
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') ;
|
Upload multiple files/directories:
'Each path is separated by '|'
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') ;
|
Download file:
Back to top
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') ;
|
Download directory:
'The last character of the path must be '\'
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') ;
|
Download multiple files/directories:
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') ;
|
Show transfer progress:
procedure TForm1.FtpLibrary1Transfer(Sender: TObject);
var speed:double;
var seconds:integer;
begin
speed:=FtpLibrary1.speed;
seconds:= FtpLibrary1.lefttime;
ProgressBar1.position:=FtpLibrary1.percent;
lblSpeed.Caption:=FtpLibrary1.formatsize(speed) + '/s';
lblRemainingTime.Caption:=FtpLibrary1.formattime(seconds);
end;
|
Get file size and last modified time:
//----------------------------
function split(const Source,ch:String):TStringList;
var
temp:String;
i:Integer;
begin
Result:=TStringList.Create;
if Source='' then exit;
temp:=Source;
i:=pos(ch,Source);
while i<>0 do
begin
Result.add(copy(temp,0,i-1));
Delete(temp,1,i);
i:=pos(ch,temp);
end;
Result.add(temp);
end;
//----------------------------
procedure TForm1.btnGetFileInfoClick(Sender: TObject);
var arrItem:TStringList;
var fileinfo:string;
var filelists:string;
begin
fileinfo:=FtpLibrary1.GetFileInfo('file.txt');
if fileinfo = '' then
application.messagebox(pchar(string(FtpLibrary1.errorinfo )) ,'Easewe software' )
else
begin
arrItem:=split(fileinfo,'*');
filelists:=filelists+string(arrItem[0])+ ' (';
filelists:=filelists+string(FtpLibrary1.formatsize(strtofloat(arrItem[1]))) +' # ';
filelists:=filelists+string(arrItem[2] + ')') ;
application.messagebox(pchar(string(filelists)),'Easewe software');
end;
end;
|
Get directory listing:Back to top
procedure TForm1.btnGetFileListClick(Sender: TObject);
var arrFile,arrItem:TStringList;
var fileinfo:string;
var filelists:string;
var i:integer;
begin
fileinfo:=FtpLibrary1.GetFileList('folder name') ;
if fileinfo = '' then
if(FtpLibrary1.errornumber=0) then
application.messagebox(pchar('Empty Directory: ' + string(txtremotepath.text)),'Easewe software')
else
application.messagebox(pchar(string(FtpLibrary1.errorinfo )) ,'Easewe software' )
else
begin
filelists:='';
arrFile:=split(fileinfo,'|');
for i:=0 to arrFile.count-1 do
begin
arrItem:=split(arrFile[i],'*');
if arrItem[0]='1' then
filelists:=filelists+'Folder:'
else
filelists:=filelists+'File :';
filelists:=filelists+string(arrItem[1])+ ' <';
if arrItem[0]='0' then
filelists:=filelists+string(FtpLibrary1.formatsize(StrToFloat(arrItem[2]))) +' , ';
filelists:=filelists+string(arrItem[3] + '>') ;
filelists:=filelists+#13;
end;
application.messagebox(pchar(string(filelists)),'Easewe software');
end;
end;
|
Back to top |
C#.Net Samples:Back
to top |
|
Connect to ftp server:
axFtpLibrary1.ServerName = "server name or ip";
axFtpLibrary1.Port = "Username";
axFtpLibrary1.Username = "Password";
axFtpLibrary1.Password = Convert.ToInt32("21");
if (axFtpLibrary1.Connect())
{
//Connected
}
else
{
MessageBox.Show("Connect failed\n" + axFtpLibrary1.ErrorInfo);
}
|
Upload file:
axFtpLibrary1.RemotePath = "file.txt";
axFtpLibrary1.LocalPath = "c:\file.txt";
if (axFtpLibrary1.Upload())
{
MessageBox.Show("Finished");
}
else
{
MessageBox.Show("Failed\n" + axFtpLibrary1.ErrorInfo);
}
|
Upload directory
'The last character of the path must be '\'
axFtpLibrary1.RemotePath = "folder\";
axFtpLibrary1.LocalPath = "c:\folder\";
if (axFtpLibrary1.Upload())
{
MessageBox.Show("Finished");
}
else
{
MessageBox.Show("Failed\n" + axFtpLibrary1.ErrorInfo);
}
|
Upload multiple files/directories:
'Each path is separated by '|'
axFtpLibrary1.RemotePath = "folder\";
axFtpLibrary1.LocalPath = "c:\file.txt|c:\folder\";
if (axFtpLibrary1.Upload())
{
MessageBox.Show("Finished");
}
else
{
MessageBox.Show("Failed\n" + axFtpLibrary1.ErrorInfo);
}
|
Download file:
Back to top
axFtpLibrary1.RemotePath = "file.txt";
axFtpLibrary1.LocalPath = "c:\file.txt";
if (axFtpLibrary1.Download())
{
MessageBox.Show("Finished");
}
else
{
MessageBox.Show("Failed\n" + axFtpLibrary1.ErrorInfo);
}
|
Download directory:
'The last character of the path must be '\'
axFtpLibrary1.RemotePath = "folder\";
axFtpLibrary1.LocalPath = "c:\folder\";
if (axFtpLibrary1.Download())
{
MessageBox.Show("Finished");
}
else
{
MessageBox.Show("Failed\n" + axFtpLibrary1.ErrorInfo);
}
|
Download multiple files/directories:
axFtpLibrary1.RemotePath = "file.txt|folder\";
axFtpLibrary1.LocalPath = "c:\folder\";
if (axFtpLibrary1.Download())
{
MessageBox.Show("Finished");
}
else
{
MessageBox.Show("Failed\n" + axFtpLibrary1.ErrorInfo);
}
|
Show transfer progress:
private void axFtpLibrary1_OnTransfer(object sender, EventArgs e)
{
double speed=axFtpLibrary1.Speed;
lblSpeed.Text = axFtpLibrary1.FormatSize(speed) + "/s";
lblPercent.Text = axFtpLibrary1.Percent().ToString() + "%";
}
|
Get file size and last modified time:
string fileinfo = axFtpLibrary1.GetFileInfo("file.txt");
//--
if (!string.IsNullOrEmpty(fileinfo))
{
string[] aryItem = fileinfo.Split('*');
MessageBox.Show(aryItem[0] + "|" + axFtpLibrary1.FormatSize(Convert.ToDouble(aryItem[1])) + "|" + aryItem[2]);
}
else
{
if (axFtpLibrary1.ErrorNumber == 0)
{
MessageBox.Show("File not exist!");
}
else
{
MessageBox.Show(axFtpLibrary1.ErrorInfo);
}
}
|
Get directory listing:Back to top
//--
string filelist = axFtpLibrary1.GetFileList("folder name");
//--
if (!string.IsNullOrEmpty(filelist))
{
string[] aryFile, aryItem;
aryFile = filelist.Split('|');
filelist = "";
for (short i = 0; i < aryFile.Length; i++)
{
aryItem = aryFile[i].Split('*');
if (aryItem[0]=="1")
{
filelist += "Folder:" + aryItem[1] + " <" + aryItem[3] + ">\n";
}
else
{
filelist += aryItem[1] + " <" +
axFtpLibrary1.FormatSize(Convert.ToDouble(aryItem[2])) + " , " + aryItem[3] + ">\n";
}
}
MessageBox.Show(filelist);
}
else
{
if (axFtpLibrary1.ErrorNumber == 0)
{
MessageBox.Show("Nothing in " + txtRemote.Text);
}
else
{
MessageBox.Show(axFtpLibrary1.ErrorInfo);
}
}
|
Back to top |
|