ftp上傳文件代碼
1、輸入命令行:-->FTP10.1.61.212如果對方沒有開啟FTP服務,那麼這個命令就不會有效果。
2、-->用戶名稱:這個主要是FTP伺服器配置的用戶名和密碼
-->用戶密碼:
3、主要是使用二進制來傳輸文件,-->bin
-->quotetpyec1381這個意思是指定伺服器端的代碼頁,如果傳輸的是IFS流文件,不用做轉換,直接用BINARY的模式傳輸文件。不會出現編碼錯誤。
4、-->lcdD:Documentdataupload這個命令主要是進去本地文件夾目錄用來上傳文件的本地路徑目錄。
5、進入主機的目錄,也就是FTP伺服器的路徑cdCBSDOTHDTA
-->put"D:/Document/data/upload/UPFW90.FRZN160919",使用put命令上傳文件。
6、put"D:/Document/data/upload/UPFW90.FRZN160919"命令執行成功之後,會在後面出來三個交易碼主要是200、150、226這都是成功的交易碼。完成效果圖。
㈡ 怎麼通過ftp傳送文本文件
不知道你的winsock是udp還是tcpip協議
這里給你一個我寫的實例我是用的udp這個發送了一段數據不一定接收就正確所以我做了校驗

'以下是接收文件的
OptionExplicit
DimFOKAsBoolean,FsAsLong,FileNumberAsInteger,LenFileAsLong '文件的長度
PrivateSubCommand1_Click()
UnloadMe
EndSub
PrivateSubCommand2_Click()
OnErrorResumeNext
DimAAsString
Me.Caption="開始下載"
IfDir(Text2.Text)<>""AndChV.Value=0Then
IfMsgBox("文件已經存在,覆蓋嗎?",vbCritical+vbYesNo)=vbYesThenKillText2.TextElseExitSub
Else
KillText2.Text
EndIf
IfText2.Text=""ThenText2.Text=Text1.Text
'Command2.Enabled=False
IfCh.Value=0ThenA="#DOW#"ElseA="#DOV#"
FMain.Wsk.SendDataA&Text1.Text
Wt1
FMain.Wsk.SendData"#DOE#"&Text2.Text
EndSub
PrivateSubForm_Load()
DimAAsString
'FMain.Ts.Enabled=True
OnErrorResumeNext
IfFMain.Cb.Text="本地組"OrFMain.Cb.Text="全部組"Then
Me.Caption="請重選下載用戶[「組」不能正確下載]"
Else
Command1.Top=-2000
Winsock0.LocalPort=FilePort
Winsock0.Bind
EndIf
EndSub
PrivateSubForm_Unload(CancelAsInteger)
OnErrorResumeNext
Winsock0.Close
Err.Clear
EndSub
PrivateSubLa_Click()
CDL.FileName=""
CDL.ShowOpen
Text2.Text=CDL.FileName
EndSub
PrivateSubWinsock0_DataArrival(ByValbytesTotalAsLong)
OnErrorResumeNext
DimFileByte()AsByte,AAsString,MendByte()AsByte,IAsLong,JAsLong,TempAsString,WAsString
Winsock0.GetDataFileByte,vbArray+vbByte'接收類型為:位元組數組
J=UBound(FileByte)'獲得包長
ForI=0To7Step2'合並包頭
Temp=Temp&Chr(FileByte(I))
Next
ForI=0To9'文件發送結束標記
A=A&Chr(FileByte(I))
Next
IfA="#ERR#"ThenWinsock0.SendData"no"
IfA="#END#"Then
ForI=0ToLen(FMain.TIn.Text)
IfI<100Then
W=Left(Right(FMain.TIn.Text,I),1)
IfW="!"Then
W=Left(Right(FMain.TIn.Text,I+4),5)
ExitFor
EndIf
Else
ExitFor
EndIf
NextI
IfW<>"下載完成!"Then
FOK=False
Me.Caption="下載完成!["&Text2.Text&"]"
FMain.TIn.Text=FMain.TIn.Text&"["&Now&"]"&"下載完成!("&Fs&"<="&LenFile&")"&vbCrLf
Command2.Enabled=True
EndIf
Else
IfVal(Temp)=JThen'比較長度看丟包沒有
ReDimMendByte(J-8)
ForI=0ToJ-8'提出包頭
MendByte(I)=FileByte(I+7)
Next
Fs=Fs+UBound(FileByte)-7
Put#FileNumber,,MendByte'寫文件
Winsock0.SendData"ok"'發送繼續發送的請求
Me.Caption="文件下載完成:["&Left(Fs/LenFile*100,4)&"%]"
Else
IfLeft(A,10)="#SENDSTA#"Then
A=""
ForI=10ToUBound(FileByte)'文件發送結束標記
A=A&Chr(FileByte(I))
Next
LenFile=Val(Left(A,InStr(A,"//")-1))
ForI=0ToLen(Text2.Text)
A=Left(Right(Text2.Text,I),1)
IfA=""ThenExitFor
Next
IfDir(Left(Text2.Text,Len(Text2.Text)-I+1),vbDirectory)=""ThenMkDirLeft(Text2.Text,Len(Text2.Text)-I+1)
'"#SENDSTA#"&FileLen(Text1.Text)&"//"&Text2.Text
FileNumber=FreeFile'取得未使用的文件號
Fs=0
OpenText2.TextForBinaryAs#FileNumber'打開文件
Else
IfA<>"#SENDEND#"Then
Winsock0.SendData"no"'出現丟包,請求重發
Else
Winsock0.SendData"#END#"'發送繼續發送的請求
Close#FileNumber
Reset
IfFOK=FalseThen
FOK=True
Me.Caption="下載完成!["&Text2.Text&"]"
FMain.TIn.Text=FMain.TIn.Text&"["&Now&"]"&"下載完成!("&Fs&"<="&LenFile&")"&vbCrLf
Command2.Enabled=True
Else
FOK=False
EndIf
EndIf
EndIf
EndIf
EndIf
EndSub
㈢ 怎麼用命令向ftp伺服器上傳文件
在本地電腦D:盤創建一個文件夾"qint"。將要上傳的文件復制到d:\qint里。通過FTP命令將文件從本地上傳到伺服器的步驟如下:
1.「開始」-「運行」-輸入「FTP」
2.open qint.ithot.net 這一步可以與第一步合並,在「運行」里直接輸入"ftp qint.ithot.net"。如果你的FTP伺服器不是用的21默認埠,假如埠是2121,那麼此步的命令應在後面空格加2121,即「open qint.ithot.net 2121」
3.username 提示你輸入用戶名
4.user1234
5.dir 你成功登陸後就可以用dir查看命令查看FTP伺服器中的文件及目錄,用ls命令只可以查看文件。
6.mkdir qint 在FTP伺服器上根目錄下建立qint目錄。
7.cd qint 進入目錄qint,用「cd 你的目錄名」可以進入當前目錄的下一級目錄,這跟DOS一樣。
8.bin 採用二進制傳輸。如果你要上傳下載,這一步很重要,不先執行這個命令,上傳下載會很慢。
9.lcd d:\qint 定位本地默認文件夾,在前面我事先在D:盤創建的。
10.!dir 查看本地文件夾中的文件及目錄*/
11.put i001.jpg
/*將當前目錄(d:\qint)中的文件i001.jpg上傳到FTP伺服器默認目錄。可以用"mput *.*"將所有文件上傳到FTP伺服器上。
㈣ 怎樣通過FTP上傳軟體把網站源代碼上傳上去
1、下載FTP軟體,安裝好;
2、新建一個連接,設置目標伺服器的埠、IP地址和目錄,意思就是說事先必須有目標伺服器的IP地址和目錄許可權,這要跟對方聯系取得。
3、雙擊新建的連接,把你想上傳的文件拖到目標目錄即可。
㈤ 如何使用ftp用curl命令上傳文件
使用ftp用curl命令上傳文件方法:
第一種:
server端有現成的ftpserver:
上傳的option是 -T
比如我們向ftp傳一個文件: curl -T localfile -u name:passwd ftp://upload_site:port/path/
curl -T hadoop_oom.log -u user:1234567 ftp://1.1.1.1/
第二種:
nginx上傳: (需要加上--with-http_dav_mole模塊 )
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_mole --with-http_ssl_mole --with-http_dav_mole
make && make install
要創建上傳的臨時目錄
mkdir -p /dev/shm/client_body_temp
nginx http段加入:
client_body_temp_path /dev/shm/client_body_temp 1 2;
client_max_body_size 1024m; #這個根據實際的情況,如有大文件upload需要加大,不然nginx拋413 error
然後:
server
{
listen 80;
server_name 1.1.1.1;
index index.html index.htm index.php;
root html;
autoindex on;
dav_methods PUT; #這個是重點默認不允許PUT
測試:
curl -T hadoop_oom.log http://1.1.1.1/
安全注意事項:
一般需要單獨location一個目錄單獨做upload用。或者這個nginx只做upload上傳單一用途。
然後就是nginx allow了,一般機房都是內網打通的,只允許idc內網才能PUT。不然就能任意PUT到你的upload機器了。
㈥ 怎麼用java實現FTP上傳
sun.net.ftp.FtpClient.,該類庫主要提供了用於建立FTP連接的類。利用這些類的方法,編程人員可以遠程登錄到FTP伺服器,列舉該伺服器上的目錄,設置傳輸協議,以及傳送文件。FtpClient類涵蓋了幾乎所有FTP的功能,FtpClient的實例變數保存了有關建立"代理"的各種信息。下面給出了這些實例變數:
public static boolean useFtpProxy
這個變數用於表明FTP傳輸過程中是否使用了一個代理,因此,它實際上是一個標記,此標記若為TRUE,表明使用了一個代理主機。
public static String ftpProxyHost
此變數只有在變數useFtpProxy為TRUE時才有效,用於保存代理主機名。
public static int ftpProxyPort此變數只有在變數useFtpProxy為TRUE時才有效,用於保存代理主機的埠地址。
FtpClient有三種不同形式的構造函數,如下所示:
1、public FtpClient(String hostname,int port)
此構造函數利用給出的主機名和埠號建立一條FTP連接。
2、public FtpClient(String hostname)
此構造函數利用給出的主機名建立一條FTP連接,使用默認埠號。
3、FtpClient()
此構造函數將創建一FtpClient類,但不建立FTP連接。這時,FTP連接可以用openServer方法建立。
一旦建立了類FtpClient,就可以用這個類的方法來打開與FTP伺服器的連接。類ftpClient提供了如下兩個可用於打開與FTP伺服器之間的連接的方法。
public void openServer(String hostname)
這個方法用於建立一條與指定主機上的FTP伺服器的連接,使用默認埠號。
public void openServer(String host,int port)
這個方法用於建立一條與指定主機、指定埠上的FTP伺服器的連接。
打開連接之後,接下來的工作是注冊到FTP伺服器。這時需要利用下面的方法。
public void login(String username,String password)
此方法利用參數username和password登錄到FTP伺服器。使用過Intemet的用戶應該知道,匿名FTP伺服器的登錄用戶名為anonymous,密碼一般用自己的電子郵件地址。
下面是FtpClient類所提供的一些控制命令。
public void cd(String remoteDirectory):該命令用於把遠程系統上的目錄切換到參數remoteDirectory所指定的目錄。
public void cdUp():該命令用於把遠程系統上的目錄切換到上一級目錄。
public String pwd():該命令可顯示遠程系統上的目錄狀態。
public void binary():該命令可把傳輸格式設置為二進制格式。
public void ascii():該命令可把傳輸協議設置為ASCII碼格式。
public void rename(String string,String string1):該命令可對遠程系統上的目錄或者文件進行重命名操作。
除了上述方法外,類FtpClient還提供了可用於傳遞並檢索目錄清單和文件的若干方法。這些方法返回的是可供讀或寫的輸入、輸出流。下面是其中一些主要的方法。
public TelnetInputStream list()
返回與遠程機器上當前目錄相對應的輸入流。
public TelnetInputStream get(String filename)
獲取遠程機器上的文件filename,藉助TelnetInputStream把該文件傳送到本地。
public TelnetOutputStream put(String filename)
以寫方式打開一輸出流,通過這一輸出流把文件filename傳送到遠程計算機
package myUtil;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import sun.net.TelnetInputStream;
import sun.net.TelnetOutputStream;
import sun.net.ftp.FtpClient;
/**
* ftp上傳,下載
*
* @author why 2009-07-30
*
*/
public class FtpUtil {
private String ip = "";
private String username = "";
private String password = "";
private int port = -1;
private String path = "";
FtpClient ftpClient = null;
OutputStream os = null;
FileInputStream is = null;
public FtpUtil(String serverIP, String username, String password) {
this.ip = serverIP;
this.username = username;
this.password = password;
}
public FtpUtil(String serverIP, int port, String username, String password) {
this.ip = serverIP;
this.username = username;
this.password = password;
this.port = port;
}
/**
* 連接ftp伺服器
*
* @throws IOException
*/
public boolean connectServer() {
ftpClient = new FtpClient();
try {
if (this.port != -1) {
ftpClient.openServer(this.ip, this.port);
} else {
ftpClient.openServer(this.ip);
}
ftpClient.login(this.username, this.password);
if (this.path.length() != 0) {
ftpClient.cd(this.path);// path是ftp服務下主目錄的子目錄
}
ftpClient.binary();// 用2進制上傳、下載
System.out.println("已登錄到\"" + ftpClient.pwd() + "\"目錄");
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
/**
* 斷開與ftp伺服器連接
*
* @throws IOException
*/
public boolean closeServer() {
try {
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
if (ftpClient != null) {
ftpClient.closeServer();
}
System.out.println("已從伺服器斷開");
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
/**
* 檢查文件夾在當前目錄下是否存在
*
* @param dir
*@return
*/
private boolean isDirExist(String dir) {
String pwd = "";
try {
pwd = ftpClient.pwd();
ftpClient.cd(dir);
ftpClient.cd(pwd);
} catch (Exception e) {
return false;
}
return true;
}
/**
* 在當前目錄下創建文件夾
*
* @param dir
* @return
* @throws Exception
*/
private boolean createDir(String dir) {
try {
ftpClient.ascii();
StringTokenizer s = new StringTokenizer(dir, "/"); // sign
s.countTokens();
String pathName = ftpClient.pwd();
while (s.hasMoreElements()) {
pathName = pathName + "/" + (String) s.nextElement();
try {
ftpClient.sendServer("MKD " + pathName + "\r\n");
} catch (Exception e) {
e = null;
return false;
}
ftpClient.readServerResponse();
}
ftpClient.binary();
return true;
} catch (IOException e1) {
e1.printStackTrace();
return false;
}
}
/**
* ftp上傳 如果伺服器段已存在名為filename的文件夾,該文件夾中與要上傳的文件夾中同名的文件將被替換
*
* @param filename
* 要上傳的文件(或文件夾)名
* @return
* @throws Exception
*/
public boolean upload(String filename) {
String newname = "";
if (filename.indexOf("/") > -1) {
newname = filename.substring(filename.lastIndexOf("/") + 1);
} else {
newname = filename;
}
return upload(filename, newname);
}
/**
* ftp上傳 如果伺服器段已存在名為newName的文件夾,該文件夾中與要上傳的文件夾中同名的文件將被替換
*
* @param fileName
* 要上傳的文件(或文件夾)名
* @param newName
* 伺服器段要生成的文件(或文件夾)名
* @return
*/
public boolean upload(String fileName, String newName) {
try {
String savefilename = new String(fileName.getBytes("GBK"),
"GBK");
File file_in = new File(savefilename);// 打開本地待長傳的文件
if (!file_in.exists()) {
throw new Exception("此文件或文件夾[" + file_in.getName() + "]有誤或不存在!");
}
if (file_in.isDirectory()) {
upload(file_in.getPath(), newName, ftpClient.pwd());
} else {
uploadFile(file_in.getPath(), newName);
}
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
return true;
} catch (Exception e) {
e.printStackTrace();
System.err.println("Exception e in Ftp upload(): " + e.toString());
return false;
} finally {
try {
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 真正用於上傳的方法
*
* @param fileName
* @param newName
* @param path
* @throws Exception
*/
private void upload(String fileName, String newName, String path)
throws Exception {
String savefilename = new String(fileName.getBytes("ISO-8859-1"), "GBK");
File file_in = new File(savefilename);// 打開本地待長傳的文件
if (!file_in.exists()) {
throw new Exception("此文件或文件夾[" + file_in.getName() + "]有誤或不存在!");
}
if (file_in.isDirectory()) {
if (!isDirExist(newName)) {
createDir(newName);
}
ftpClient.cd(newName);
File sourceFile[] = file_in.listFiles();
for (int i = 0; i < sourceFile.length; i++) {
if (!sourceFile[i].exists()) {
continue;
}
if (sourceFile[i].isDirectory()) {
this.upload(sourceFile[i].getPath(), sourceFile[i]
.getName(), path + "/" + newName);
} else {
this.uploadFile(sourceFile[i].getPath(), sourceFile[i]
.getName());
}
}
} else {
uploadFile(file_in.getPath(), newName);
}
ftpClient.cd(path);
}
/**
* upload 上傳文件
*
* @param filename
* 要上傳的文件名
* @param newname
* 上傳後的新文件名
* @return -1 文件不存在 >=0 成功上傳,返迴文件的大小
* @throws Exception
*/
public long uploadFile(String filename, String newname) throws Exception {
long result = 0;
TelnetOutputStream os = null;
FileInputStream is = null;
try {
java.io.File file_in = new java.io.File(filename);
if (!file_in.exists())
return -1;
os = ftpClient.put(newname);
result = file_in.length();
is = new FileInputStream(file_in);
byte[] bytes = new byte[1024];
int c;
while ((c = is.read(bytes)) != -1) {
os.write(bytes, 0, c);
}
} finally {
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
}
return result;
}
/**
* 從ftp下載文件到本地
*
* @param filename
* 伺服器上的文件名
* @param newfilename
* 本地生成的文件名
* @return
* @throws Exception
*/
public long downloadFile(String filename, String newfilename) {
long result = 0;
TelnetInputStream is = null;
FileOutputStream os = null;
try {
is = ftpClient.get(filename);
java.io.File outfile = new java.io.File(newfilename);
os = new FileOutputStream(outfile);
byte[] bytes = new byte[1024];
int c;
while ((c = is.read(bytes)) != -1) {
os.write(bytes, 0, c);
result = result + c;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}
/**
* 取得相對於當前連接目錄的某個目錄下所有文件列表
*
* @param path
* @return
*/
public List getFileList(String path) {
List list = new ArrayList();
DataInputStream dis;
try {
dis = new DataInputStream(ftpClient.nameList(this.path + path));
String filename = "";
while ((filename = dis.readLine()) != null) {
list.add(filename);
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
public static void main(String[] args) {
FtpUtil ftp = new FtpUtil("192.168.11.11", "111", "1111");
ftp.connectServer();
boolean result = ftp.upload("C:/Documents and Settings/ipanel/桌面/java/Hibernate_HQL.docx", "amuse/audioTest/music/Hibernate_HQL.docx");
System.out.println(result ? "上傳成功!" : "上傳失敗!");
ftp.closeServer();
/**
* FTP遠程命令列表 USER PORT RETR ALLO DELE SITE XMKD CDUP FEAT PASS PASV STOR
* REST CWD STAT RMD XCUP OPTS ACCT TYPE APPE RNFR XCWD HELP XRMD STOU
* AUTH REIN STRU SMNT RNTO LIST NOOP PWD SIZE PBSZ QUIT MODE SYST ABOR
* NLST MKD XPWD MDTM PROT
* 在伺服器上執行命令,如果用sendServer來執行遠程命令(不能執行本地FTP命令)的話,所有FTP命令都要加上\r\n
* ftpclient.sendServer("XMKD /test/bb\r\n"); //執行伺服器上的FTP命令
* ftpclient.readServerResponse一定要在sendServer後調用
* nameList("/test")獲取指目錄下的文件列表 XMKD建立目錄,當目錄存在的情況下再次創建目錄時報錯 XRMD刪除目錄
* DELE刪除文件
*/
}
}
㈦ ftp文件下載和上傳命令
windows下ftp上傳文件:
比如要把 D:\index.html上傳至伺服器的根目錄中,可以鍵入:
ftp> put D:\index.html (回車)
當屏幕提示你已經傳輸完畢,可以鍵入相關命令查看:
ftp> dir (回車)
windows下ftp上傳下載:
假設要把伺服器\images目錄中的所有.jpg文件下載至本機中,可以輸入指令:
ftp> cd images(回車) [註:進入\images目錄]
ftp> mget *.jpg
windows下ftp上傳與下載工作完畢,鍵入bye中斷連接。
ftp> bye(回車)
下面是一些常用的FTP命令:
1. open:與伺服器相連接;
2. send(put):上傳文件;
3. get:下載文件;
4. mget:下載多個文件;
5. cd:切換目錄;
6. dir:查看當前目錄下的文件;
7. del:刪除文件;
8. bye:中斷與伺服器的連接。
如果想了解更多,可以鍵入
ftp> help (回車)
㈧ linux下用shell編程FTP上傳文件的問題
Linux下用shell編程實現ftp自動登錄上傳文件,代碼如下:
####把本地/home/databachup/a.sh up ftp /home/databackup 下####
#!/bin/bash
ftp -n<<!
open FTP伺服器IP地址
user FTP賬戶 FTP密碼
binary
cd /home/data
lcd /home/databackup
prompt
put a.sh a.sh #要上傳的文件
close
bye
!
