当前位置:首页 » 文件管理 » ftp上传文件代码

ftp上传文件代码

发布时间: 2023-03-06 20:18:41

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
!

热点内容
内置存储卡可以拆吗 发布:2025-05-18 04:16:35 浏览:336
编译原理课时设置 发布:2025-05-18 04:13:28 浏览:378
linux中进入ip地址服务器 发布:2025-05-18 04:11:21 浏览:612
java用什么软件写 发布:2025-05-18 03:56:19 浏览:32
linux配置vim编译c 发布:2025-05-18 03:55:07 浏览:107
砸百鬼脚本 发布:2025-05-18 03:53:34 浏览:944
安卓手机如何拍视频和苹果一样 发布:2025-05-18 03:40:47 浏览:742
为什么安卓手机连不上苹果7热点 发布:2025-05-18 03:40:13 浏览:803
网卡访问 发布:2025-05-18 03:35:04 浏览:511
接收和发送服务器地址 发布:2025-05-18 03:33:48 浏览:372