我想知道如何用PHP从服务器上的一个目录复制文件并将其粘贴到另一个目录中.我有一个系统,当用户注册创建一个名称与用户名相同的子目录时,我想从名为users的子目录中复制一个名为profile.php的文件,并将其粘贴到具有用户名的新目录中?
我有代码将文件上传到服务器.
import org.apache.commons.net.ftp.FTPClient;
import java.io.File;
import java.io.IOException;
import org.apache.commons.net.ftp.FTPFile;
import java.io.FileInputStream;
import java.net.SocketException;
public class FtpConnectDemo {
public static void main(String[] args) throws SocketException, IOException{
FTPClient client = new FTPClient();
FileInputStream fis = null;
client.connect("ftp.someserver.co.uk",21);
boolean login = client.login("webmaster@someserver.co.uk",
"mypassword");
String filename = "E:/workbench j2ee/cPEP_UI/WebContent/engine.xml";
client.storeFile(filename, fis);
client.logout();
fis.close();
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,它给了我这个错误:
Exception in thread "main" java.lang.NullPointerException
at FtpConnectDemo.main(FtpConnectDemo.java:22)
Run Code Online (Sandbox Code Playgroud)
用户名,密码,服务器名称都可以.那怎么了?我可以使用telnet连接到FTP.有任何想法吗?
好的,现在我没有得到nullpointer异常,因为我初始化了fis.但我的文件尚未上传; 可能是什么问题?
我编写了一个ruby脚本,使用ftp/net从ftp站点检索数据.除了尝试下载文件本身时超时的最后阶段,一切似乎都运行良好.任何想法为什么会这样?'samples'现在有一个目录用于测试目的.
ftp = Net::FTP.new('ftp.sra.ebi.ac.uk')
ftp.login
puts "connected!"
errors = []
samples = ["SRR016000"]
samples.each do |sample|
files = ftp.chdir("vol1/fastq/SRR016/#{sample}/")
puts "changed directory"
#files = ftp.list('SRR*')
begin
Timeout.timeout(20) do
ftp.getbinaryfile("#{sample}_1.fastq.gz")
end
rescue Timeout::Error
errors << "File download timed out for: #{sample}"
puts errors.last
end
end
ftp.close
puts "All done!"
Run Code Online (Sandbox Code Playgroud) 如何使用FTP在服务器上运行.jar(Java)文件?我使用该ftp命令进入服务器,提供IP地址,用户名,密码.是否可以运行java文件?
我在perl中使用Net :: FTP来进行一些文件传输.当我运行以下代码时: -
使用IP地址有什么问题吗?我是否正确在主机领域提供此功能?
use strict;
use Net::FTP;
my $host = "10.77.69.124";
my $user = "administrator";
my $password = "Password";
my $f = Net::FTP->new($host, Debug =>0) or die "Can't open $host\n";
$f->login($user, $password) or die "Can't log $user in\n";
Run Code Online (Sandbox Code Playgroud)
代码无法连接到远程主机.为什么会这样?这不应该与提供的IP地址一起工作$host吗?
我正在尝试使用QFtp将.avi文件上传到FTP服务器:
void MyFTP::recordingDone(QString &fileName){
remainingFiles.push_back(new QString(fileName));
commands[qftp.connectToHost(globalProperties.ftpServer)] = "connect to host";
commands[qftp.login(globalProperties.ftpUsername,globalProperties.ftpPassword)] = "login";
commands[qftp.cd("myapp")] = "cd myapp";
commands[qftp.cd("Videos")] = "cd videos";
QDir().cd(globalProperties.videoStorageLocation);
qDebug()<<"Opening "<<fileName<<endl;
if(QFile::exists(fileName)){
qDebug()<<"File exists"<<endl;
}
else{
qDebug()<<"File does not exist"<<endl;
}
QFile file(fileName);
qDebug()<<"putting"<<endl;
qftp.put(&file,fileName);
qDebug()<<"Closing ftp"<<endl;
qftp.close();
}
Run Code Online (Sandbox Code Playgroud)
我已连接到命令完成信号并使用插槽调试输出信息:
void TrusionFTP::ftpCommandDone(int id, bool error){
qDebug()<<"command: "<<commands[id]<<": "<<error;
if(error){
qDebug()<<qftp.errorString()<<endl;
if (qftp.hasPendingCommands()){
qDebug()<<"Pending commands"<<endl;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是崩溃前的输出:
Opening "2012-Mar-06-12-19-57.avi"
File exists
putting
Closing ftp
command: "connect to host" : false
command: "login" : false
command: …Run Code Online (Sandbox Code Playgroud) 我一直在乱用C#中的TCP套接字,我在与我设置的FTP服务器通信时遇到了一些麻烦.我最初可以连接并获得220消息,但是当我发送"USER nrcrast"命令时,我从未得到响应,并且DataAvailable属性返回false.谁知道我做错了什么?到目前为止,这是我的代码:
namespace TCPClient
{
public partial class TCPClientForm : Form
{
private TcpClient myClient;
NetworkStream stream;
public TCPClientForm()
{
InitializeComponent();
send();
}
void send()
{
while (true)
{
try
{
myClient = new TcpClient("nrcrast.dyndns.info", 21);
break;
}
catch (SocketException ex)
{
Console.WriteLine(ex.ToString());
}
}
stream = myClient.GetStream();
int sendOffset = 0;
int recOffset=0;
int dataLength;
Byte[] receiveData = new Byte[256];
// wait for a response
dataLength = stream.Read(receiveData, recOffset, receiveData.Length);
String recvdMessage = System.Text.Encoding.ASCII.GetString(receiveData, 0, dataLength);
Console.WriteLine(recvdMessage.ToString());
recOffset+=dataLength;
String …Run Code Online (Sandbox Code Playgroud) 我可以使用标准Java类进行FTP操作(上传,下载,删除,列表......)吗?因为,我找到了一个很好的FTP客户端librabry Apache Commons Net,但我的经理想根据标准类编写自己的.
如何让我的经理允许我们使用上面的包,如果她不购买这个库的使用,我们可能会遇到什么陷阱?
我正在尝试通过PHP脚本与同一服务器上的3个网站建立FTP连接.它适用于2个站点,但第3个我得到以下错误(它似乎不是临时的):
"警告:ftp_connect()[function.ftp-connect]:php_network_getaddresses:getaddrinfo failed:这通常是主机名解析期间的临时错误,意味着本地服务器没有收到来自权威服务器的响应"
此代码段是失败的地方:
$server = 'ftp.'.$ftp_server;
$conn_id = ftp_connect($server) OR die("<br>unable to establish an FTP connection");
Run Code Online (Sandbox Code Playgroud)
我希望有人能指出我正确的方向.
关心所有人
当file_get_contents()用于在ftp://ipaddress/somefile.txt的FTP服务器上获取文本文件的文件内容时,我收到以下错误:
警告:file_get_contents()[ function.file-get-contents ]:connect()失败:第1行的filename.php中的权限被拒绝
但是当我在webbrowser中访问ftp://ipaddress/somefile.txt时,它绝对没有问题.
为什么我的浏览器可以打开文本文件,但file_get_contents()不能?
PS:我不知道它是否与它有关,但ini指令allow_url_fopen已经开启.