doyhq66282
2010-07-20 14:16
浏览 259
已采纳

ftp_put上传一个空文件

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.

图片转代码服务由CSDN问答提供 功能建议

我正在尝试通过ftp_put将文件上传到Windows服务器。 < p>我的代码如下:

  $ 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)){
 echo“FTP连接 失败了!”;  
退出; 
}其他{
 echo“连接到FTP服务器”; 
} 
 
 $ upload = ftp_put($ conn_id,$ file_name,$ file_location,FTP_ASCII); 
 
 //检查 上传状态
if(!$ upload){
 echo“FTP上传失败!”;  
} else {
 echo“File Uploaded”; 
} 
 
 //关闭FTP流
ftp_close($ conn_id);  
   
 
 

如果我使用filezilla手动上传文件,它可以完美地运行。 如果我使用上面的代码,它会创建一个空文件。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

5条回答 默认 最新

  • donglinxia1541 2010-07-21 10:25
    最佳回答

    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)

    评论
    解决 无用
    打赏 举报
查看更多回答(4条)

相关推荐 更多相似问题