Inside a Script Task you can use the Dts namespace to retrieve connections; you should use the Connections property and execute the AcquireConnection function to retrieve the relevantSqlConnection class (You need to perform a explicit cast operation in order to do that) as example:
SqlConnection myOLEDBConnection = Dts.Connections["OLEDB Connection"].AcquireConnection(Dts.Transaction) as SqlConnection;
For flat files, connection use the same logic but the result is a string:
string FFConnection = Dts.Connections["FlatFile Connection"].AcquireConnection(Dts.Transaction) as string;