If you like SEOmastering Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

FTP file creation

Started by Walalayo, 09-20-2011, 03:33:02

Previous topic - Next topic

WalalayoTopic starter

Hi
I need to create a file on the server using ftp via a PHP script.I can make a directory and connect etc ok, but I don't know how to create a file and put contents in etc. Thanks very much


portodon

<?php$file = 'somefile.txt';$remote_file = 'readme.txt';// set up basic connection$conn_id = ftp_connect($ftp_server);// login with username and password$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);// upload a fileif (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) { echo "successfully uploaded $file\n";} else { echo "There was a problem while uploading $file\n";}// close the connectionftp_close($conn_id);?>
newbielink:http://www.marketing.szczecin.pl [nonactive]
  •  

Lishmalinyjames

Open Control Panel.
Click on System and Security.
Click on Administrative Tools.
Double-click the Internet Information Services (IIS) Manager shortcut.
On the "Connections" pane, right-click Sites, and select the Add FTP Site option.


saravanan28

View the 'FTP overview' article to log into your server using an FTP client.
Make sure your client is configured to show hidden files.
Once you're logged in, make sure you're in the correct directory to create the file. ...
Right click and choose 'Create new file'.
  •  

john2020

To create a file on the server using FTP via a PHP script, you can use the `ftp_put` function. Here's an example:

```php
<?php

// Server details
$server = "example.com";
$username = "your_username";
$password = "your_password";

// File details
$remoteFile = "/path/to/file.txt";
$localFile = "/path/to/local/file.txt";

// Create an FTP connection
$conn = ftp_connect($server);
if (!$conn) {
    die("Failed to connect to FTP server.");
}

// Login to the FTP server
if (!ftp_login($conn, $username, $password)) {
    die("FTP login failed.");
}

// Upload a file
if (ftp_put($conn, $remoteFile, $localFile, FTP_ASCII)) {
    echo "File uploaded successfully.";
} else {
    echo "Failed to upload file.";
}

// Close the connection
ftp_close($conn);

?>
```

Make sure to replace "example.com" with your server's hostname, "your_username" and "your_password" with your FTP credentials, and "/path/to/file.txt" and "/path/to/local/file.txt" with the appropriate paths for your file.

This code connects to the FTP server, logs in with the provided credentials, and then uses the `ftp_put` function to upload the local file to the remote server. The `FTP_ASCII` parameter specifies the transfer mode as ASCII; you can change it to `FTP_BINARY` if you need to transfer binary files.

Once you run this script, it will either display "File uploaded successfully" or "Failed to upload file" based on the success of the operation.
  •  

deepika@2876

Use ftp_fput() in PHP, write your content to a temp file locally, then upload it to the server to create the file.
  •  


If you like SEOmastering Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...