简体   繁体   English

通过PHP将文件上传到SFTP服务器(phpseclib)

[英]Upload files to SFTP server via PHP (phpseclib)

I have CSVs that I want to upload to the 'incoming' folder in the SFTP server. 我有CSV,我想上传到SFTP服务器中的'incoming'文件夹。 I am using phpseclib to do this. 我正在使用phpseclib来做到这一点。 The connection is already there but it does not output anything. 连接已经存在,但它不输出任何内容。

I'm not sure if what I did was correct since I haven't dealt with SFTP before. 我不确定我做的是否正确,因为我之前没有处理过SFTP。 Here's what my code looks like: 这是我的代码的样子:

$file = "leads.csv";

$server = "41.160.150.200";
//$server = "ft.bayport.co.za";
$port = "22";
$username = "";
$password = ""; 

//username and password removed for security reasons

set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');

include 'Net/SFTP.php';

define('NET_SFTP_LOGGING', NET_SFTP_LOG_COMPLEX); // or NET_SFTP_LOG_SIMPLE

$sftp = new Net_SFTP($server);

// Check SFTP Connection
if (!$sftp->login($username, $password)) {
    echo 'Login Failed.';
    echo $sftp->getSFTPLog();
}else{

echo 'Connected to SFTP.';

echo $sftp->pwd();

// Upload CSVs to SFTP incoming folder
     echo $upload = $sftp->put("incoming/".$file, "./bayport/".$file, NET_SFTP_LOCAL_FILE);

}

I would really appreciate any help. 我真的很感激任何帮助。 Thanks! 谢谢!

Now I know what's the problem with the script. 现在我知道脚本的问题是什么。

The remote directory URL was wrong. 远程目录URL错误。 "incoming/" should be "/incoming/" “incoming /”应为“/ incoming /”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM