Uploading file into ftp server
Moderator: General Moderators
-
YoussefSiblini
- Forum Contributor
- Posts: 206
- Joined: Thu Jul 21, 2011 1:51 pm
Uploading file into ftp server
Hi,
I am trying to upload an excel file into an ftp server, I connected to the ftp but am getting an error saying that the file couldn't upload.
I am new to php and I need to sort this ASAP please help, here is the code:
//Send the FTP Connection and send the Excel file to the ftp server
$ftp_server = "xxxxxxxxx";
$ftp_user = "xxxx";
$ftp_pass = "xxxxxxxxxx";
$file = 'xls/AB-MXRPayment.xls';
$fp = '/AB-MXRPayment.xls';
// set up a connection or die
$conn_id = ftp_connect($ftp_server , 20 ) or die("Couldn't connect to $ftp_server");
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "Connected as $ftp_user@$ftp_server\n";
} else {
echo "Couldn't connect as $ftp_user\n";
}
if (@ftp_put($conn_id, $fp, $file, FTP_ASCII)) {
echo "Successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
// close the connection
ftp_close($conn_id);
and here is the answer I am getting:
Connected as user1@80.45.12.74 There was a problem while uploading xls/AB-MXRPayment.xls
Youssef
I am trying to upload an excel file into an ftp server, I connected to the ftp but am getting an error saying that the file couldn't upload.
I am new to php and I need to sort this ASAP please help, here is the code:
//Send the FTP Connection and send the Excel file to the ftp server
$ftp_server = "xxxxxxxxx";
$ftp_user = "xxxx";
$ftp_pass = "xxxxxxxxxx";
$file = 'xls/AB-MXRPayment.xls';
$fp = '/AB-MXRPayment.xls';
// set up a connection or die
$conn_id = ftp_connect($ftp_server , 20 ) or die("Couldn't connect to $ftp_server");
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "Connected as $ftp_user@$ftp_server\n";
} else {
echo "Couldn't connect as $ftp_user\n";
}
if (@ftp_put($conn_id, $fp, $file, FTP_ASCII)) {
echo "Successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
// close the connection
ftp_close($conn_id);
and here is the answer I am getting:
Connected as user1@80.45.12.74 There was a problem while uploading xls/AB-MXRPayment.xls
Youssef
-
YoussefSiblini
- Forum Contributor
- Posts: 206
- Joined: Thu Jul 21, 2011 1:51 pm
Re: Uploading file into ftp server
This code is uploading the file into a port 21 ftp server but not in port 20 ftp server, I thought this information will help you more?
Re: Uploading file into ftp server
XLS files should probably be transferred in FTP_BINARY mode.
Do you know what the @ operator does?
Do you know what the @ operator does?
-
YoussefSiblini
- Forum Contributor
- Posts: 206
- Joined: Thu Jul 21, 2011 1:51 pm
Re: Uploading file into ftp server
No, no idea what @ operator does, what confusing me is that this code is working and uploading the xls file in port 21 but not port 20.
Youssef
Youssef
Re: Uploading file into ftp server
If you don't know what something does, research it: search the Web; read the manual. Curiosity is an essential trait for a successful programmer.
The @ operator suppresses error messages. Without error messages, it is difficult to diagnose a problem. So, the first thing to do is remove both of the at-signs and see what errors appear.
Based on the output you say the script delivers, it looks like the ftp_put() function is where the problem occurs.
The @ operator suppresses error messages. Without error messages, it is difficult to diagnose a problem. So, the first thing to do is remove both of the at-signs and see what errors appear.
Based on the output you say the script delivers, it looks like the ftp_put() function is where the problem occurs.
-
YoussefSiblini
- Forum Contributor
- Posts: 206
- Joined: Thu Jul 21, 2011 1:51 pm
Re: Uploading file into ftp server
Hi, you are right, I took them before off and I got an error and I researched that error and I never sorted it out, So at the end I put them back, OK now I am in same problem again I took them off and I am getting this error:
Warning: ftp_put() [function.ftp-put]: Opening data channel for file transfer. in /home/abmxrcom/public_html/ipn.php on line 189
and this is the line 189: if (ftp_put($conn_id, $fp, $file, FTP_ASCII))
Youssef
Warning: ftp_put() [function.ftp-put]: Opening data channel for file transfer. in /home/abmxrcom/public_html/ipn.php on line 189
and this is the line 189: if (ftp_put($conn_id, $fp, $file, FTP_ASCII))
Youssef
Re: Uploading file into ftp server
Try enabling passive mode with ftp_pasv().
-
YoussefSiblini
- Forum Contributor
- Posts: 206
- Joined: Thu Jul 21, 2011 1:51 pm
Re: Uploading file into ftp server
Hi Thank you for all your help, I enabled passive mode and I am getting this error:
Connected as user1@80.45.12.74
Warning: ftp_put() [function.ftp-put]: php_connect_nonb() failed: Operation now in progress (115) in /home/abmxrcom/public_html/ipn.php on line 189
Warning: ftp_put() [function.ftp-put]: Type set to I in /home/abmxrcom/public_html/ipn.php on line 189
There was a problem while uploading xls/AB-MXRPayment.xls
If you want, I can give you the ftp server details, I will really appreciate if you can help me in this.
Youssef
Connected as user1@80.45.12.74
Warning: ftp_put() [function.ftp-put]: php_connect_nonb() failed: Operation now in progress (115) in /home/abmxrcom/public_html/ipn.php on line 189
Warning: ftp_put() [function.ftp-put]: Type set to I in /home/abmxrcom/public_html/ipn.php on line 189
There was a problem while uploading xls/AB-MXRPayment.xls
If you want, I can give you the ftp server details, I will really appreciate if you can help me in this.
Youssef
Re: Uploading file into ftp server
Why not use port 21?
-
YoussefSiblini
- Forum Contributor
- Posts: 206
- Joined: Thu Jul 21, 2011 1:51 pm
Re: Uploading file into ftp server
It will not connect to the server if I used port 21, I have tried !!!
Re: Uploading file into ftp server
YoussefSiblini wrote:This code is uploading the file into a port 21 ftp server but not in port 20 ftp server,
YoussefSiblini wrote:this code is working and uploading the xls file in port 21 but not port 20.
I'm confused. Twice you said it works on port 21; now you say it doesn't.YoussefSiblini wrote:It will not connect to the server if I used port 21,
-
YoussefSiblini
- Forum Contributor
- Posts: 206
- Joined: Thu Jul 21, 2011 1:51 pm
Re: Uploading file into ftp server
Yes I can see that I really confused you sorry for that I will clear things for you.
Lets say there are 2 servers I want to connect and upload the file into:
1- Server A (I use port 21 to connect and the file upload normally and every thing work good)
2- Server B (I use port 20 because if used port 21 to connect it doesn't connect, in this server where I am talking about now, I am able to connect to the server using port 20 but getting message saying: Connected as user1@80.45.12.74
Warning: ftp_put() [function.ftp-put]: php_connect_nonb() failed: Operation now in progress (115) in /home/abmxrcom/public_html/ipn.php on line 189
Warning: ftp_put() [function.ftp-put]: Type set to I in /home/abmxrcom/public_html/ipn.php on line 189
There was a problem while uploading xls/AB-MXRPayment.xls
Youssef
Lets say there are 2 servers I want to connect and upload the file into:
1- Server A (I use port 21 to connect and the file upload normally and every thing work good)
2- Server B (I use port 20 because if used port 21 to connect it doesn't connect, in this server where I am talking about now, I am able to connect to the server using port 20 but getting message saying: Connected as user1@80.45.12.74
Warning: ftp_put() [function.ftp-put]: php_connect_nonb() failed: Operation now in progress (115) in /home/abmxrcom/public_html/ipn.php on line 189
Warning: ftp_put() [function.ftp-put]: Type set to I in /home/abmxrcom/public_html/ipn.php on line 189
There was a problem while uploading xls/AB-MXRPayment.xls
Youssef
Re: Uploading file into ftp server
Is it necessary to be connected to both servers at the same time?
-
YoussefSiblini
- Forum Contributor
- Posts: 206
- Joined: Thu Jul 21, 2011 1:51 pm
Re: Uploading file into ftp server
No Server A is a test server, but I want to use server B.
Re: Uploading file into ftp server
So, connect to Server A. Do stuff. Close the connection. Connect to Server B. Do stuff. Close the connection. For both connections, connect on port 21. Will that work?
FTP uses port 21 to communicate control information and port 20 for transferring file data.
FTP uses port 21 to communicate control information and port 20 for transferring file data.