Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8498259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:21:14+00:00 2026-06-11T00:21:14+00:00

I am trying to write a powershell script which call the .ftp file (

  • 0

I am trying to write a powershell script which call the .ftp file (http://www.scriptftp.com). When Powershell call the .ftp script file which is use to upload a zip file to ftp server

here is my upload.ftp file code

OPENHOST("www.abcd.in","sdfdsfs","pwd")
CHDIR("/dirctory/from/user/")

$result=PUTFILE("D:\MyZipTest.zip")

IF($result!="OK")
    PRINT("ERROR in GetFile, exiting")
    # Exit with error code 1
    EXIT(1)
ELSE
    EXIT()
    PRINT("File uploaded successfuly")
END IF

CLOSEHOST

In Above code i return EXIT(1) or EXIT(0) to calling method ie powershell script file

my powershell script file code:

Invoke-Item "D:\USER\Raj\BLACKswastik DEV\FTPScript\Upload1.ftp"

Start-Sleep -Second 15

echo $lastexitcode

echo $?

here i want to fetch exit code which return by .ftp file script so i use $lastexitcode and $? but both of them not showing me proper results.
IS there any other way to fetch the exit code of child process please suggest me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:21:15+00:00Added an answer on June 11, 2026 at 12:21 am

    Try using Start-Process. You can get back a Process object that you can query later for an exit code e.g.:

    $ftpPath = "D:\USER\Raj\BLACKswastik DEV\FTPScript\Upload1.ftp"
    $p = Start-Process <path_to_scriptftp.exe> -Wait -PassThru -ArgumentList $ftpPath
    $p.ExitCode
    

    The problem with using Invoke-Expression (or launching the exe directly) is that you’re launching a Windows subsystem EXE and unlike a console subsystem exe, Invoke-Expression will return right after the exe has launched (and before it exits). Invoke-Item also returns before the Windows EXE has exited.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a powershell script which will execute sqlcmd.exe to run a
I'm trying to write a script in powershell that i can use to get
I trying to write a PowerShell script (learning at the same time). I have
I'm trying to write a powershell script that updats each of the DiagnosticsConnectionString and
I'm trying to write a custom powershell script that will create a local user
I am trying to write a powershell script that will take in a text
I'm having a problem here trying to upload a file with powershell. What I'm
I am trying to use powershell to script some tasks within internet explorer. This
I'm trying to write a PowerShell script that will do the following: Executes a
I am trying to write a PowerShell script to replace the contents of tags

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.