1

I have to upload a text file on my android project and so I used the IdFTP. This is the code:

Button2.Enabled:=False;
Label5.Text:='Uploading...';

Memo1.Lines.Add(Edit1.Text+':'+ComboBox1.Items.Text);
Memo1.SaveToFile('filehost.txt');

try
 IdFTP1.Connect;
  // I set the host, password and username
 IdFTP1.Put('filehost.txt');
finally
 IdFTP1.Disconnect;

I am having a problem because when I run the app on my Samsung (Android 2.3) I have an error that says Cannot create file "/filehost.txt". Not a directory.

I must save the content of that Memo1 in my Android device and then upload it using the IdFTP. How can I do it avoiding that error?

1

1 Answer 1

3

You can't write to the root folder. Use TPath to find a writable folder, such as from TPath.GetTempPath() or TPath.GetDocumentsPath().

Alternatively, do not use a file at all. TIdFTP.Put() has an overloaded version that uploads a TStream instead of a file, eg:

var
  MS: TMemoryStream;
begin
  MS := TMemoryStream.Create;
  try
    Memo1.Lines.SaveToStream(MS);
    MS.Position := 0;
    ...
    IdFTP1.Put(MS, 'filehost.txt');
    ...
  finally
    MS.Free;
  end;
end;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.