ftp_put上传一个空文件 [英] ftp_put uploads an empty file

查看:135
本文介绍了ftp_put上传一个空文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的代码如下:

  $ date = date('ymd'); 
$ file_name = $ date。'。csv';
$ file_location ='D:/inetpub/wwwroot/website.com/html/assets /'.$ file_name;

//设置基本连接
$ conn_id = ftp_connect(FTP_HOST,FTP_PORT);

//使用用户名和密码登录
$ login_result = ftp_login($ conn_id,FTP_USER,FTP_PASS);

检查连接
if((!!conn_id)||(!$ login_result)){
echoFTP连接失败!
出口;
} else {
echo连接到FTP服务器;


$ upload = ftp_put($ conn_id,$ file_name,$ file_location,FTP_ASCII);

//检查上传状态
if(!$ upload){
echoFTP upload has failed!;
} else {
echoFile Uploaded;
}

//关闭FTP流
ftp_close($ conn_id);

如果我使用filezilla手动上传文件,它可以很好地工作。如果我使用上面的代码,它会创建一个空文件。

解决方案

事实证明,UKFast阻止了连接和传输。 (他们也要求它只是活动模式)。



现在他们已经解除封锁了,它的运作非常好。 (之前似乎只是超时)

I'm trying to upload a file via ftp_put to a windows server.

my code is as follows:

    $date           = date('ymd');
    $file_name      = $date.'.csv';
    $file_location  = 'D:/inetpub/wwwroot/website.com/html/assets/'.$file_name;

//set up basic connection
$conn_id = ftp_connect(FTP_HOST, FTP_PORT);

// login with username and password
$login_result = ftp_login($conn_id, FTP_USER, FTP_PASS);

// check connection
if ((!$conn_id) || (!$login_result)) { 
    echo "FTP connection has failed!"; 
    exit;
}  else { 
    echo "Connected to FTP Server";
}

$upload = ftp_put($conn_id, $file_name, $file_location, FTP_ASCII);

// check upload status
if (!$upload) { 
    echo "FTP upload has failed!"; 
} else { 
    echo "File Uploaded";
}

// close the FTP stream 
ftp_close($conn_id); 

If I upload the file manually using filezilla, it works perfectly. If I use the code above, it creates an empty file.

解决方案

It turns out that UKFast was blocking the connection and transfer. (They also require it to be Active Mode only).

Now they've unblocked it, it's working perfectly. (Before it seemed to just time out)

这篇关于ftp_put上传一个空文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆